How does the JSON.parse() method works in JavaScript ?
Last Updated :
30 Jan, 2024
The JSON.parse()
method in JavaScript is used to parse a JSON (JavaScript Object Notation) string and convert it into a JavaScript object. JSON is a lightweight data-interchange format that is easy for humans to read and write, and it is also easy for machines to parse and generate.
Example: Here, JSON.parse()
take a JSON-formatted string (jsonString
) and converts it into a JavaScript object (parsedObject
). Once parsed, you can access the properties of the object as you would with any other JavaScript object.
Javascript
const jsonString =
'{"name": "John", "age": 30, "city": "New York"}' ;
const parsedObject = JSON.parse(jsonString);
console.log(parsedObject.name);
console.log(parsedObject.age);
console.log(parsedObject.city);
|
Share your thoughts in the comments
Please Login to comment...