by Sai gowtham

How to convert a JSON string into a JavaScript object

To convert a JSON string into a JavaScript object, we can use the JSON.parse() method by passing the string as an argument to it.

Here is an example that converts the user JSON string to a JavaScript object.

const userString = '{"name":"coach","age":12,"active":false}';

const userObject = JSON.parse(userString);

console.log(userObject);

Output:

 {
 active: false,
 age: 12,
 name: "coach"
}

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
130,921 students enrolled
48.5 hours of video content
View Course