Reputation: 15258
What is wrong in parsing following JSON data
'{
{"errors":
{"firstname":"is too short"}
},
{"account":
{"firstname":"Test"}
}
}'
for which a get this error?
JSON::ParserError in AccountsController#home
706: unexpected token at ... # the code above
?
In the AccountsController I have
JSON.parse(json_data)["errors"]
Upvotes: 1
Views: 1226
Reputation: 21180
You should not encapsulate the attribute errors and account. It should probably look like this:
'{
"errors":{"firstname":"is too short"},
"account":{"firstname":"Test"}
}'
Upvotes: 4
Reputation: 6580
You're missing property names:
'{"property1":
{"errors":
{"firstname":"is too short"}
},
"property2":
{"account":
{"firstname":"Test"}
}
}'
Or, you really wanted an array:
'[
{"errors":
{"firstname":"is too short"}
},
{"account":
{"firstname":"Test"}
}
]'
Upvotes: 3
Reputation: 4478
Your data struct appears to be a JSON object {} but you have an array []. The first set of {} should be [].
Upvotes: 1