JavaScript (ES2026) reference · JSON and Global Functions

JavaScript JSON.parse() Method

Turn a JSON string into a JavaScript value. Throws SyntaxError on invalid JSON; an optional reviver transforms values.

JavaScript (ES2026) Since ES5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

JSON.parse(text, reviver)

Parameters

ParameterDescription
text A JSON string.
reviver optional A function (key, value) that can transform each value.

Return value

The parsed value (object, array, string, number, boolean or null).

Examples

Parse an objectTry it yourself
const user = JSON.parse('{"name":"Ada","skills":["math","code"],"active":true}');
console.log(user.name, user.skills.length, user.active);

Output

Ada 2 true
Invalid JSON throwsTry it yourself
try {
  JSON.parse("{name: 'Ada'}"); // keys and strings need double quotes
} catch (e) {
  console.log(e.name);
}

Output

SyntaxError
Revive datesTry it yourself
const data = JSON.parse('{"created":"2026-10-22T10:00:00Z"}', (key, value) =>
  key === "created" ? new Date(value) : value);
console.log(data.created.getUTCFullYear(), data.created instanceof Date);

Output

2026 true

Common mistakes

  • JSON needs double quotes around keys and strings, and doesn't allow trailing commas or comments.
  • Dates come back as strings; convert them with a reviver or new Date().
  • Always wrap JSON.parse() of external input in try…catch.

Version history

VersionChange
JavaScript ES5Added

Was this page helpful?