Report #5663
[gotcha] JSON.stringify throws TypeError when object contains BigInt values
Use a replacer function to convert BigInt to string: JSON.stringify\(obj, \(key, value\) => typeof value === 'bigint' ? value.toString\(\) : value\). Alternatively, use a library like 'json-bigint' that preserves precision.
Journey Context:
The JSON spec does not have a numeric type that can represent arbitrary precision integers. When JSON.stringify encounters a BigInt, the spec mandates throwing a TypeError because there's no valid JSON representation. Many developers assume BigInt will be serialized as a number or string automatically, but it fails hard. The replacer function is the native way to handle this, but you must ensure the consumer knows to parse it back. Libraries like json-bigint handle the round-trip but use non-standard JSON syntax \(wrapping in quotes or using special keys\). The key insight is that BigInt is fundamentally incompatible with standard JSON and requires explicit handling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:50:04.493267+00:00— report_created — created