JSON.parse() reads a JSON text string and returns the matching JavaScript value—object, array, string, number, boolean, or null.
It only accepts strict JSON (double-quoted keys/strings, no trailing commas, no comments). Invalid text throws SyntaxError. Use try/catch for network or user input.
Beginner path.
Parse valid text → handle errors → try a reviver if you need type tweaks. Next: JSON.stringify().
Reference
Syntax
JSON
JSON.parse(text)
JSON.parse(text, reviver)
textA string containing JSON. Must be valid JSON grammar.
reviverOptional (key, value) => … to transform or drop values while building the result.
Compare
Valid vs Invalid
Side by side: text JSON.parse accepts vs text that throws.
Valid — parses
JSON
{
"name": "Ada",
"age": 36
}
Double-quoted keys and strings. No trailing comma.
Invalid — SyntaxError
Not JSON
{
name: 'Ada',
age: 36,
}
Unquoted keys, single quotes, and a trailing comma all fail.
Validate
After Parse
JSON.parse checks syntax only. It does not check that fields exist or have the types your app expects.
For shape and types, use JSON Schema (or your own checks) on the value you got back—especially for untrusted API payloads.
Return a new value to replace, or return value unchanged.
Frequently Asked Questions
A JavaScript value matching the JSON text: object, array, string, number, boolean, or null. Missing keys are simply absent—not undefined properties you must read.
No. Trailing commas, single-quoted strings, and // comments are invalid JSON. JSON.parse throws SyntaxError.
An optional function (key, value) that runs on each value while the result is built. You can transform types, drop keys (return undefined), or leave values unchanged.
No. eval runs any JavaScript. JSON.parse only accepts JSON text. Always use JSON.parse for API and file JSON—never eval.