Answers for "json.stringify format output"

17

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);
Posted by: Guest on June-20-2020
0

json.stringify

json.stringify() is useful for, say, converting an object to a string format
which enbales it to be sent as data to a server or for use in other 
languages

json.parse() turns a string object back into a regular object
Posted by: Guest on January-23-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language