object to json javascript
var obj = {name: "Martin", age: 30, country: "United States"};
// Converting JS object to JSON string
var json = JSON.stringify(obj);
console.log(json);
// Prints: {"name":"Martin","age":30,"country":"United States"}
"https://www.tutorialrepublic.com/faq/how-to-convert-js-object-to-json-string.php"
// Imagine we received this text from a web server:
'{ "name":"John", "age":30, "city":"New York"}'
// To convert text into a JavaScript object, use the JavaScript function JSON.parse():
var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
// OR
var string = '{ "name":"John", "age":30, "city":"New York"}';
var obj = JSON.parse(string);
console.log(JSON.stringify({ x: 5, y: 6 }));
// expected output: "{"x":5,"y":6}"
console.log(JSON.stringify([new Number(3), new String('false'), new Boolean(false)]));
// expected output: "[3,"false",false]"
console.log(JSON.stringify({ x: [10, undefined, function(){}, Symbol('')] }));
// expected output: "{"x":[10,null,null,null]}"
console.log(JSON.stringify(new Date(2006, 0, 2, 15, 4, 5)));
// expected output: ""2006-01-02T15:04:05.000Z""