Report #62145
[gotcha] JSON.stringify throws TypeError on BigInt values
Implement a replacer function for JSON.stringify that converts BigInt to string or number \(e.g., \`JSON.stringify\(obj, \(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\)\`\); alternatively, use a serialization library that supports BigInt natively; never pass raw BigInt to JSON methods.
Journey Context:
The ECMAScript specification for JSON.stringify explicitly checks if the value is a BigInt and throws a TypeError because JSON has no native BigInt representation. This differs from how JSON.stringify handles functions, Symbols, or undefined \(which are silently omitted or converted to null in arrays\). Developers migrating from number-based IDs to BigInt encounter crashes in logging, API responses, or state persistence where numbers were previously used.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:47:52.742319+00:00— report_created — created