← Back to Blog

JSON.stringify vs JSON.parse: Complete Guide

Understand JSON.stringify() and JSON.parse() in JavaScript: serialization, deserialization, replacer functions, reviver functions, and common pitfalls.

JSON.stringify()

Converts a JavaScript value to a JSON string. The optional replacer and space parameters control output.

JSON.stringify(obj)           // compact\nJSON.stringify(obj, null, 2)  // pretty-printed\nJSON.stringify(obj, ['name']) // only include 'name' key

JSON.parse()

Converts a JSON string back to a JavaScript value. The optional reviver function transforms values during parsing.

JSON.parse(str)\nJSON.parse(str, (key, val) => key === 'date' ? new Date(val) : val)

Common Pitfalls

  • Circular references throw TypeError
  • undefined, functions, and Symbols are omitted
  • Date objects become strings (no auto-revival)
  • BigInt throws TypeError (use replacer)

Try It Free

Use our free online tool — 100% client-side, no data leaves your browser.

Open JSON Formatter

Related Tools & Articles