javascript json stringify string code example
Example 1: Javascript object to JSON string
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
Example 2: node json stringify
let data = {
name: "John Smith",
age: 30,
hobbies: ["Programming", "Video Games"]
};
// {name:"John Smith",age:30,hobbies:["Programming","Video Games"]}
let miny = JSON.stringify(data);
// The 4 parameter signifys 4 spaces. You can also use "\t".
/* {
* name: "John Smith",
* age: 30,
* ...
*/
let pretty = JSON.stringify(data, null, 4);