by Sai gowtham

Convert a JavaScript Object to JSON String

In this tutorial, we are going to learn about how to convert a JavaScript object to a JSON string.

Using JSON.stringify method

In JavaScript, we have a JSON.stringify() method which is used to convert an object into a string.

Let’s see an example.

consider we have an object like this.

const obj = {name:"king",age:10,city:"New York"};

Now, we are converting the above object into a string by using the JSON.stringfy() method.

console.log(JSON.stringify(obj));

// output --> {"name":"king","age":10,"city":"New York"}

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 JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course