JavaScript Object Notation (JSON) is a light-weight data storage format for storing and transmitting data, stored in the form of key-value pairs. What sets JSON apart from other data formats is its human-readable and self-describing properties.
JSON.parse
method do?Most of the times, the data given is not in JSON format and must be converted into JSON before you can use it. That’s where the JSON.parse
method comes into play. It converts a JSON string to a JSON object, which can then be used, changed and stored to a JSON file.
Let’s see how we can use the JSON.parse
method to convert a string, data
, into a JSON object.
var data = '{"platform": "Educative", "established": 2015}';json = JSON.parse(data);console.log(json.platform); // expected output: Educativeconsole.log(json.established); // expected output: 2015
Free Resources