Trusted answers to developer questions

What is JSON.parse in JavaScript?

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

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.

Data in JSON format
Data in JSON format

What does the 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.


Example

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: Educative
console.log(json.established); // expected output: 2015

RELATED TAGS

json
stringify
js
javascript
parse
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?