Report #15194
[gotcha] JSON.stringify silently strips undefined/functions/symbols and throws on BigInt
Implement a replacer function to handle BigInt \(convert to string or throw explicit error\), and explicitly check for undefined in object values before serialization if you need to distinguish between property absence and undefined values. Never rely on JSON to preserve undefined or distinguish between sparse and dense arrays with undefined holes.
Journey Context:
JSON.stringify applies specific rules that cause silent data loss: undefined values in objects are omitted \(not serialized as 'undefined'\), undefined in arrays become null, functions and symbols are ignored entirely. BigInt throws a TypeError because there is no JSON representation. This creates a footgun when caching API responses or storing state—BigInt crashes the serialization, and undefined properties disappear causing cache misses on retrieval. The fix requires a replacer that handles BigInt explicitly \(e.g., converting to string with a reviver pattern\) and pre-validation of data structures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:23:37.049049+00:00— report_created — created