Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to parse JSON

var test = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
console.log('testing parsing', test);

 

i have used this sample josn to parse but i am unable to parse.

 

Can anyone help me to get it right.

 

Thanks in advance

Best Answer
0 Votes
5 REPLIES 5

What is the error?

Best Answer
0 Votes

I get [object] [object] when i parse the response

Best Answer
0 Votes

thats because it is an object. you need to specify what exactly you want to see.

 

try

 

console.log('testing parsing', test.name);

Best Answer
0 Votes

...or you could try console.log(JSON.stringify(test)) if you don't mind going around in a circle. 🙂

 

I'm also not convinced that " are beneficial around object attribute names; eg, for "name".

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thank you so much for your input.

As you said that is object. 

Best Answer
0 Votes