Report #5946
[gotcha] JSON.stringify throws TypeError when encountering BigInt values
Implement a replacer function that explicitly converts BigInt to String, or use a library like json-bigint. Pattern: \`JSON.stringify\(obj, \(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\)\`. Document the schema to ensure consumers rehydrate strings back to BigInt.
Journey Context:
BigInt handles integers beyond 2^53-1, but ECMA-404 \(JSON spec\) has no BigInt representation. ECMA-262 mandates that JSON.stringify throw a TypeError for BigInt, unlike other primitives that coerce to string. Developers often assume automatic string conversion or try \`toJSON\(\)\` methods \(which BigInt lacks\). Common mistakes include forgetting nested BigInts or converting to Number \(losing precision\). The fix must be explicit; relying on implicit conversion silently fails or throws.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:42:36.077224+00:00— report_created — created