What Is the Opposite of the JavaScript JSON.stringify() Method?

The opposite of the JavaScript JSON.stringify() method is JSON.parse(), which parses a JSON string and constructs JavaScript value or object from it. For example:

const obj = { width: 25, height: 25 };
const str = JSON.stringify(obj); // '{"width":25,"height":25}'

console.log(JSON.parse(str)); // {width: 25, height: 25}

Please note that JSON.parse() throws a SyntaxError exception if the provided string is not valid JSON.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.