JSON: parse & stringify in JavaScript
JSON is JavaScript's data interchange format with a strict subset syntax (double quotes, no functions/undefined/comments, no trailing commas). JSON.stringify converts values (dropping functions/undefined/symbols, throwing on circular refs) with replacer functions/arrays and space indentation for pretty output; JSON.parse reverses with optional reviver transforms (date revival being classic).
Structured cloning (structuredClone()) deep-copies richer values (Maps, Sets, Dates, circular!) where JSON round-trips fall short — but JSON remains the wire format for APIs and storage everywhere.
stringify serializes
JSON.stringify({a: 1}) → '{"a":1}' — functions/undefined/symbols dropped silently, circular refs throw.
parse with validation
JSON.parse(text) throws SyntaxError on malformed input — always try/catch untrusted payloads.
Replacer/reviver transform
Replacer functions filter/alter during stringify; revivers (new Date(v)) restore types during parse.
Clone beyond JSON
structuredClone() deep-copies Maps, Dates, typed arrays, even circular graphs — where JSON cannot go.
let user = { name: "Ada", tags: ["dev"] };let text = JSON.stringify(user);let back = JSON.parse(text);console.log(text.length > 0, back.tags[0]);Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.