how to stringify json code example
Example 1: turn object into string javascript
var obj = {a: "a", b: "b" };
var string = JSON.stringify(obj);
Example 2: how take values from JSON.stringify($('form').serialize())
1 var formData = $('#form').serializeObject();
2 $.extend(formData, { Contacts : myContacts});
3 $.extend(formData, { Address : myAddress});
4 var result = JSON.stringify(formData);
5
Example 3: convert json.stringify to array in javascript
const myObj = {
name: 'Skip',
age: 2,
favoriteFood: 'Steak'
};
const myObjStr = JSON.stringify(myObj);
console.log(myObjStr);
console.log(JSON.parse(myObjStr));
Example 4: 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 5: 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 6: how to use json stringify in javascript
var Num=[1,2,3,4,5,6]
console.log("The Numbers Are "+JSON.stringify(Num))