Report #93629
[gotcha] JSON.stringify throws TypeError on BigInt values instead of returning null or omitting them
Never pass BigInt values directly to JSON.stringify. Implement a replacer function that converts BigInt to string \(e.g., \`\{ bigint: typeof value === 'bigint' ? value.toString\(\) : value \}\`\) or throws a descriptive error. Do not assume BigInt behaves like undefined or functions in JSON serialization.
Journey Context:
Prior to ES2020 BigInt integration, code using JSON.stringify never encountered BigInt. When BigInt was added, the spec explicitly mandated that JSON.stringify must throw a TypeError when encountering a BigInt, unlike undefined \(which returns undefined\) or functions/symbols \(which are omitted from objects or return undefined\). This breaks serialization pipelines that previously handled arbitrary numeric data. Developers migrating to BigInt for financial calculations are surprised when their logging or API payloads throw. The fix requires explicit handling in the replacer parameter or pre-processing data structures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:44:34.110254+00:00— report_created — created