Report #23136
[gotcha] JSON.stringify throws TypeError on BigInt values breaking serialization of large integers
Implement a replacer function: \`JSON.stringify\(obj, \(key, value\) => typeof value === 'bigint' ? value.toString\(\) : value\)\` or use a library like \`json-bigint\` that handles parsing back to BigInt; alternatively, convert BigInts to strings before serialization.
Journey Context:
BigInt was added to handle 64-bit integers \(e.g., Twitter snowflake IDs, financial ledgers\) that exceed Number.MAX\_SAFE\_INTEGER. However, JSON spec \(RFC 8259\) does not define a BigInt type—numbers are IEEE 754 doubles. When JSON.stringify encounters a BigInt, the spec \(ECMA-262\) mandates a TypeError rather than silent truncation. This crashes serialization pipelines that previously worked with smaller numbers. Developers often try \`BigInt.asIntN\(64, value\)\` not realizing the JSON limitation. The fix requires a replacer to serialize as string \(losing type info on parse\) or using a specialized library. This impedance mismatch between JS's numeric tower and JSON's simplicity is a silent architecture trap.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T17:14:21.803321+00:00— report_created — created