Javscript Json code example
Example 1: change js to json
var obj = {name: "Martin", age: 30, country: "United States"};
var json = JSON.stringify(obj);
console.log(json);
"https://www.tutorialrepublic.com/faq/how-to-convert-js-object-to-json-string.php"
Example 2: json javascript
myObj = {name: "John", age: 31, city: "New York"};
myJSON = JSON.stringify(myObj);
localStorage.setItem("testJSON", myJSON);
text = localStorage.getItem("testJSON");
obj = JSON.parse(text);
document.getElementById("demo").innerHTML = obj.name;
Example 3: create a json object in javascript
var employee = {
"firstName": firstName,
"lastName": lastName
}