Reputation: 263
I'm trying to simulate a json response by attaching it to a variable.
myjson = {'link':{
'href':'erwerweirwierwe',
'rel':'self'
},
'plan':{
'shortName':'Chrome',
'shortKey':'MASTERFULL',
'type':'chain',
'enabled':true,
'link':{
'href':'something',
'rel':'self'
},
'key':'MASTERFULL',
'name':'teserere'
}
when i try to parse the above, i get an error:
parsedJson = JSON.parse(myjson)
do i need to format the raw json before reading it this way?
Upvotes: 0
Views: 99
Reputation: 15159
You have to use double quotes, not single quotes.
You can validate your json using this web service.
Also, in your example, you're missing the last closing brace.
The following JSON validates:
{
"link": {
"href": "erwerweirwierwe",
"rel": "self"
},
"plan": {
"shortName": "Chrome",
"shortKey": "MASTERFULL",
"type": "chain",
"enabled": true,
"link": {
"href": "something",
"rel": "self"
},
"key": "MASTERFULL",
"name": "teserere"
}
}
Upvotes: 2