Hey guys in this post, we will discuss converting JSON string into a javascript object
Convert Javascript object into a JSON String check here
By using JSON.parse() method
We can use JSON.parse() method to convert JSON string into a javascript object. We should pass the JSON string as a parameter to the parse() method.
Syntax:
JSON.parse(json_string);
Example
Consider the following employee JSON –
const employeeJSON = `{"name":"Bushan","age":28,"location":"India"}`;
Use JSON.parse() to convert it to javascript object
const employeeObj = JSON.parse(employeeJSON);
console.log("Employee Object:", employeeObj);
Output:
Employee Object: {name: "Bushan", age: 28, location: "India"}