lundi 21 avril 2014

Attempting to use invalid JSON in Ruby


Vote count:

0




I'm trying to make a test to verify that invalid json in a curl returns a 400 error code. Unfortunately, Ruby won't allow me to use invalid JSON.



if bad_json
credentials = {
"username" => username
"password" => password
}.to_json
else
credentials = {
"username" => username,
"password" => password
}.to_json
end


produces the following when I try to run the test:



/foo.rb:60: syntax error, unexpected tSTRING_BEG, expecting '}'
"password" => password
^
/foo.rb:60: syntax error, unexpected =>, expecting keyword_end
"password" => password
^ (SyntaxError)


Is it possible to pass this invalid JSON in without the script breaking?



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire