Handling JSON Data in Javascript


Parse and stringify JSON with JSON.parse() and JSON.stringify().

Source Code

let json = '{"name": "John", "age": 30}';
let person = JSON.parse(json); // Convert JSON string to object
console.log(person.name); // "John"

let obj = {name: 'Jane', age: 25};
let jsonString = JSON.stringify(obj); // Convert object to JSON string
console.log(jsonString); // '{"name":"Jane","age":25}'
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments