On this page
JSON.stringify
Prev: parse | Up: JSON | Next: Reflect
Rel: JSON, JSON, Math, BigInt & Date Guide
Ref: MDN Web Docs — JSON.stringify
Tags: #public #web #javascript #builtins #json #tier/core
Signature & Overview
JSON.stringify(value, replacer?, space?)
Serializes a JavaScript value to a JSON string (pass space = 2 for pretty-printing).
Notes & Pitfalls
- Silently drops
undefined, functions, andSymbolproperties (and convertsundefinedin arrays tonull), and throwsTypeErroron circular objects orBigInt.
Example
const pretty = JSON.stringify({ a: 1, b: undefined, c: [2, 3] }, null, 2);
console.assert(pretty.includes('"a": 1') && !pretty.includes('"b"'));
Linked from
Related notes
- tuts/javascript/builtins/JSON/parse 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/Reflect 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