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"
1function isJson(str) {
2 try {
3 let value = JSON.parse(str);
4 return value
5 } catch (e) {
6 return str;
7 }
8}
9
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);
1var j = {0: "Hello", 1: " ", 2: "World", 3: "!"};
2
3console.log(Object.values(j))
4// Object.values(j) = ["Hello"," ","World","!"]