how to print json object value in javascript code example
Example 1: js print object as json
var obj = {
a: 1,
b: 2,
c: { d: 3, e: 4 }
};
console.log(JSON.stringify(obj));
console.log(JSON.stringify(obj, null, 2));
Example 2: convert data into json format in javascript
Use the JavaScript function JSON.parse() to convert text into a JavaScript object:
var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
Example 3: json object
var myObj, x;
myObj = {"name":"John", "age":30, "car":null};
x = myObj.name;
document.getElementById("demo").innerHTML = x;