August 9, 2026

How to Parse JSON in JavaScript

How to Parse JSON in JavaScript

Because JSON is derived from JavaScript, parsing and generating it is built directly into the language via the global JSON object.

Parsing JSON String to an Object

Use JSON.parse() to convert a JSON string into a JavaScript object.

const jsonString = '{"name": "Alice", "age": 25}';
const user = JSON.parse(jsonString);

console.log(user.name); // Output: Alice

Converting an Object to JSON String

Use JSON.stringify() to convert a JavaScript object into a JSON string.

const user = { name: "Bob", active: true };
const jsonString = JSON.stringify(user);

console.log(jsonString); // Output: '{"name":"Bob","active":true}'

Pretty Printing

You can also format the output using the third argument:

const prettyJson = JSON.stringify(user, null, 2);

If you want to convert raw JSON directly into an ES6 module, check out our JSON to JavaScript Converter.