Reputation: 43
I am trying to parse JSON data in my Rails 5 application with JSON.parse. I keep getting this error:
"#<JSON::ParserError: 785: unexpected token at ': Hours,\n \"config\": {\n \"blocks\": <\n {\n \"type\": table,\n \"name\": Hours from Users,\n \"fields\": [\n \"customer\",\n \"project\",\n \"user\",\n \"task\",\n \"hour_type\",\n \"amount\"\n ]\n }\n >\n }>"
Upvotes: 1
Views: 6298
Reputation: 11
Change from :json
to :hybrid
like:
Rails.application.config.action_dispatch.cookies_serializer = :hybrid
as explained in this Rails issue:
Upvotes: 1
Reputation: 1895
here is what it looks like if you print the message:
#<JSON::ParserError: 785: unexpected token at ': Hours,
"config": {
"blocks": <
{
"type": table,
"name": Hours from Users,
"fields": [
"customer",
"project",
"user",
"task",
"hour_type",
"amount"
]
}
>
}>
you forgot to quote certain values like table
and Hours from Users
, they need double-quotes "
to be valid json.
(also not sure about the extra <
and >
, might be coming from the parser error)
Upvotes: 2