// Storing data:
myObj = {name: "John", age: 31, city: "New York"};
myJSON = JSON.stringify(myObj);
localStorage.setItem("testJSON", myJSON);
// Retrieving data:
text = localStorage.getItem("testJSON");
obj = JSON.parse(text);
document.getElementById("demo").innerHTML = obj.name;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Json Tutorial</title>
</head>
<body>
<div class="container">This is my container</div>
<script>
let jsonObj = {
name: "Harry",
channel: "CWH",
friend: "Rohan Das",
food: "Bhindi" //#bhindiLoverSquad
}
console.log(jsonObj);
let myJsonStr = JSON.stringify(jsonObj);
console.log(myJsonStr);
myJsonStr = myJsonStr.replace('Harry', 'Larry');
console.log(myJsonStr)
newJsonObj = JSON.parse(myJsonStr);
console.log(newJsonObj)
</script>
</body>
</html>
var obj = {name: 'John', age: 20}
// to json
var json = JSON.stringify(obj);
//json to object
var obj1 = JSON.parse(json);
// JSON syntax
{
"name": "John",
"age": 22,
"gender": "male",
}
{
"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
}