1var obj = {name: "Martin", age: 30, country: "United States"};
2
3// Converting JS object to JSON string
4var json = JSON.stringify(obj);
5
6console.log(json);
7// Prints: {"name":"Martin","age":30,"country":"United States"}
8"https://www.tutorialrepublic.com/faq/how-to-convert-js-object-to-json-string.php"
1var jsonPerson = '{"first_name":"billy", "age":23}';
2var personObject = JSON.parse(jsonPerson); //parse json string into JS object
1const json = '{ "fruit": "pineapple", "fingers": 10 }';
2const obj = JSON.parse(json);
3console.log(obj.fruit, obj.fingers);
1const json = '{"result":true, "count":42}';
2const obj = JSON.parse(json);
3
4console.log(obj.count);
5// expected output: 42
6
7console.log(obj.result);
8// expected output: true
1var jsonPerson = '{"first_name":"billy", "age":23}';
2var personObject = JSON.parse(jsonPerson); //parse json string into JS object