1Parse the data with JSON.parse(), and the data becomes a JavaScript object.
2When using the JSON.parse() on a JSON derived from an array, the method will return a JavaScript array, instead of a JavaScript object.
1var jsonPerson = '{"first_name":"billy", "age":23}';
2var personObject = JSON.parse(jsonPerson); //parse json string into JS object
1const json = '{ "fruit": "pineapple", "fingers": 10 }';
2const obj = JSON.parse(json);
3console.log(obj.fruit, obj.fingers);
1const json = '{"result":true, "count":42}';
2const obj = JSON.parse(json);
3
4console.log(obj.count);
5// expected output: 42
6
7console.log(obj.result);
8// expected output: true
1The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
2
3