Ruby on Rails JSON.parse unexpected token error
By : Daniele Spera
Date : March 29 2020, 07:55 AM
Any of those help Well, we can only answer based on the part of the JSON you showed us, but it has two problems: All the quote characters (") are escaped; they don't need to be unless they are used in a double-qoted string, which it appears they are not. You are missing a closing brace (}).
|
Ruby json parse error: unexpected token
By : Jelnet
Date : March 29 2020, 07:55 AM
To fix this issue You tried to parse the filename as JSON, which won't work. Instead, you need to read the file first: code :
parse = JSON.parse(File.read(f))
|
Ruby JSON.parse gives unexpected token error
By : user2655200
Date : March 29 2020, 07:55 AM
I wish this help you params[:username] contains string (me@example.com) which is not a valid JSON. You don't need to call JSON.parse on this.
|
Why does Ruby 2.3.0 JSON.parse give unexpected token error?
By : CSharper
Date : March 29 2020, 07:55 AM
This might help you There seems to be an issue with having a comma after the last object in your array: code :
\"createdAt\": \"2014-10-22T03:00:00.407Z\"\n },\n ],\n \"count\": 2\n}\n"
^ This comma
JSON.parse("{\n \"notices\": [\n {\n \"id\": \"1234\",\n \"projectId\": 1,\n \"groupId\": \"55\",\n \"createdAt\": \"2014-10-22T03:00:00.407Z\"\n },\n {\n \"id\": \"1234\",\n \"projectId\": 1,\n \"groupId\": \"55\",\n \"createdAt\": \"2014-10-22T03:00:00.407Z\"\n } ],\n \"count\": 2\n}\n")
=> {"notices"=>[{"id"=>"1234", "projectId"=>1, "groupId"=>"55", "createdAt"=>"2014-10-22T03:00:00.407Z"}, {"id"=>"1234", "projectId"=>1, "groupId"=>"55", "createdAt"=>"2014-10-22T03:00:00.407Z"}], "count"=>2}
|
Ruby on Rails JSON.parse "unexpected token" error
By : Rajeswari Dadiboyina
Date : March 29 2020, 07:55 AM
I hope this helps you . Looks like error response is not returned as JSON. You could do something like: code :
def reviews
JSON.parse(reviews_json)['Reviews']
rescue JSON::ParserError
[]
end
|