Parse JSON in JavaScript

javascript

Updated August 29, 2026

Parse JSON text with JSON.parse() and serialize JavaScript data with JSON.stringify():

const text = '{"name":"Ada","active":true}';

try {
  const user = JSON.parse(text);
  console.log(user.name);
} catch (error) {
  console.error('Invalid JSON:', error.message);
}

const output = JSON.stringify({ ok: true });

JSON.parse() accepts text, not a JavaScript object. It rejects comments, trailing commas, and single-quoted strings. Parsing does not validate that the data has the fields or types your application expects, so validate untrusted input before using it. A JSON payload can contain unexpected keys or very large values.

Never replace JSON.parse() with eval(); evaluating input executes code. For network responses, check the HTTP status and content type before parsing. JSON.stringify() omits undefined object properties and cannot represent values such as functions, so it is not a lossless clone mechanism.

Sources

related.

Ruslan Osipov

Ruslan Osipov

About the author