Report #18025
[gotcha] JSON.stringify throws TypeError on BigInt and silently omits keys with undefined values or function properties
Use a replacer function to handle BigInt: JSON.stringify\(obj, \(key, value\) => typeof value === 'bigint' ? value.toString\(\) : value\). For undefined values that must be preserved, convert to null explicitly or use a serialization library that supports undefined. Never pass objects with circular references to JSON.stringify without a flatted library or custom handling.
Journey Context:
Unlike undefined in objects \(omitted\) vs arrays \(converted to null\), BigInt is strictly non-serializable per ECMA-262 and throws a TypeError, halting execution. Functions are silently dropped from objects. This asymmetry causes data loss in logging and IPC: \{ count: 5n, fn: \(\) => \{\} \} serializes to \{\} after throwing on the BigInt if not handled. Developers expect toString-like coercion but the spec enforces strict type safety for interoperability with JSON's IEEE 754 number limitations \(BigInt exceeds safe integer range\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:57:50.303906+00:00— report_created — created