How to Convert the JSON string to object using JavaScript
In this tutorial, we are going to learn about how to convert the JSON string into a Object in JavaScript with the help of examples.
Using JSON.parse() method
To convert a JSON string into a object, we can use the built-in JSON.parse()
method in JavaScript.
The JSON.parse()
method takes the JSON string as an argument and retruns the Object.
Here is an example:
const userString = '{"name":"coach","age":12,"active":false}';
const userObject = JSON.parse(userString);
console.log(userObject);
Output:
{
active: false,
age: 12,
name: "coach"
}