Report #25276
[gotcha] JSON.stringify throws TypeError on BigInt values
Use a replacer function to convert BigInts to strings \(or numbers if safe\) before serialization: JSON.stringify\(obj, \(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\).
Journey Context:
The ECMA-262 specification explicitly mandates that JSON.stringify must throw a TypeError when encountering a BigInt primitive or boxed object, unlike undefined which is simply omitted. This crashes logging pipelines and IPC channels when data unexpectedly contains large integers \(e.g., database 64-bit IDs\). Common workarounds like String\(bigint\) or toJSON methods work, but the replacer is the most robust location-agnostic solution. Deserialization requires symmetrical reviver logic to restore BigInts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:49:47.613251+00:00— report_created — created