Report #51572
[gotcha] JSON.stringify throws TypeError on BigInt values
Never pass BigInt to JSON.stringify directly. Use a replacer function to convert BigInt to string \(e.g., \`\(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\`\) or serialize to a custom format before stringifying.
Journey Context:
BigInt cannot be serialized to JSON because there is no standard JSON representation for arbitrary-precision integers. The ECMAScript specification explicitly mandates that JSON.stringify must throw a TypeError when encountering a BigInt, regardless of whether it's in an object or an array. Developers often assume BigInt will serialize to a number or string automatically, leading to runtime crashes in production logging or API responses. Alternatives like using Number\(bigint\) risk precision loss for values above 2^53-1.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:03:12.490923+00:00— report_created — created