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
Syntax
JSON.parse(text, reviver)
Parameters
| Parameter | Description |
|---|---|
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
const user = JSON.parse('{"name":"Ada","skills":["math","code"],"active":true}');
console.log(user.name, user.skills.length, user.active);
Output
Ada 2 true
try {
JSON.parse("{name: 'Ada'}"); // keys and strings need double quotes
} catch (e) {
console.log(e.name);
}
Output
SyntaxError
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 intry…catch.
Version history
| Version | Change |
|---|---|
| JavaScript ES5 | Added |
Related
JSON.stringify()· Convert a JavaScript value to a JSON string, optionally filtering keys and pretty-printing with indentation.structuredClone()· Create a deep copy of a value, including nested objects, arrays, Dates, Maps and Sets. Functions can't be cloned.- JavaScript JSON · tutorial