Karthick Karthick - 1 month ago 7
Ruby Question

Ruby on Rails - JSON parse error unexpected token

I read json file after load it into json but i got error JSON::ParserError unexpected token at, i couldn't json parse.Below i mentioned what i got output after file read

Here my code,

file = File.read("sample.json")
hash = JSON.load(file)


after read my json file,

"{\"rename\"=>[{\"from\"=>\"TTTC\", \"to\"=>\"AAAB\"}, {\"from\"=>\"AAAA\", \"to\"=>\"Description\"}, {\"from\"=>\"AAAC\", \"to\"=>\"test\"}], \"drop\"=>{\"fields\"=>[\"AAAG\", \"AAAH\"]}}"

Answer

This is not valid in json =>. JSON looks like

{ "rename": [{ "from": "TTTC" }] }