Convert a JSON String to Object in JavaScript

Source code :

var JSONString = '{ "name":"John", "age":30, "city":"New York"}';
var obj = JSON.parse(JSONString);
alert( obj.name + ", " + obj.age);

Output :


                

Algorithm :

  1. Parse a string with JSON.parse()
  2. Access the string with object name
  3. Finally print the result

Output :


                

Comments :