On this page
JSON.parse
Prev: JSON | Up: JSON | Next: stringify
Rel: JSON, JSON, Math, BigInt & Date Guide
Ref: MDN Web Docs — JSON.parse
Tags: #public #web #javascript #builtins #json #tier/core
Signature & Overview
JSON.parse(text, reviver?)
Parses a JSON string into a JavaScript value; throws SyntaxError on invalid input.
Notes & Pitfalls
- Always wrap in
try / catchfor external input (SyntaxErroron invalid JSON). - Pass a
reviver(key, val)to revive ISO date strings or guard against__proto__keys.
Example
const data = JSON.parse('{"id":1,"ok":true}');
console.assert(data.id === 1 && data.ok === true);
Linked from
Related notes
- tuts/javascript/builtins/JSON/stringify Linked here; links to this page; shared tags: #builtins, #javascript, #json, #tier, #web
- tuts/javascript/builtins/JSON Linked here; links to this page; shared tags: #builtins, #javascript, #json, #web
- tuts/javascript/builtins/json_math_and_date Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/Array/at shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/filter shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/find shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/flatMap shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/from shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/includes shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/isArray shared tags: #builtins, #javascript, #tier, #web