json stringify to json code example
Example 1: json stringify pretty
JSON.stringify(jsonobj,null,'\t')
Example 2: js print object as json
var obj = {
a: 1,
b: 2,
c: { d: 3, e: 4 }
};
console.log(JSON.stringify(obj));
console.log(JSON.stringify(obj, null, 2));
Example 3: 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 4: json stringify and parse
var Jazzman = new Object();
Jazzman.altura = 1.85;
Jazzman.edad = 41;
Jazzman.colorOjos = "azul";
salidaJSON = JSON.stringify(Jazzman)
console.log(salidaJSON);
var jsonTexto = '{"color":"blanco","km":100000,"esNuevo":false,"rueda":{"marca":"desconocida","estado":"malo"}}';
var coche = JSON.parse(jsonTexto);
console.log(coche);
Example 5: how to use json stringify in javascript
var Num=[1,2,3,4,5,6]
console.log("The Numbers Are "+JSON.stringify(Num))