json stringfy code example
Example 1: json stringify pretty
JSON.stringify(jsonobj,null,'\t')
Example 2: turn object into string javascript
var obj = {a: "a", b: "b" };
var string = JSON.stringify(obj);
Example 3: Javascript object to JSON string
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
Example 4: json.stringify parameters
var person={"first_name":"Tony","last_name":"Hawk","age":31};
console.log(JSON.stringify(person , null , 4));
> "{
"first_name": "Tony",
"last_name": "Hawk",
"age": 31
}"
Example 5: node json stringify
let data = {
name: "John Smith",
age: 30,
hobbies: ["Programming", "Video Games"]
};
let miny = JSON.stringify(data);
let pretty = JSON.stringify(data, null, 4);
Example 6: js json stringfy beutify
JSON.stringify(obj, undefined, 2);