How to Convert JS Object to JSON String

  1314 views   2 years ago Javascript

Use the JSON.stringify() Method

You can use the JSON.stringify() method to easily convert a JavaScript object a JSON string.

Let's take a look at the following example to see how this basically works:

// Sample JS object
var obj = {name: "Martin", age: 30, country: "United States"};
// Converting JS object to JSON string
var json = JSON.stringify(obj);
// Prints: {"name":"Martin","age":30,"country":"United States"}


Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]