Report #15981
[gotcha] JSON.stringify throws TypeError on BigInt values instead of serializing them
Use a replacer function to convert BigInt to string: \`JSON.stringify\(obj, \(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\)\`, and parse with a reviver to convert back, or use a library like \`json-bigint\` that handles this automatically
Journey Context:
The JSON specification \(ECMA-404\) has no BigInt type. When \`JSON.stringify\` traverses the object graph, if it encounters a BigInt primitive \(step 11.a of SerializeJSONProperty\), it throws a TypeError immediately. This is unlike \`undefined\` \(skipped in objects\) or functions \(return undefined\). Developers assume BigInt will coerce to string or number like other primitives, but it is a hard error. This breaks serialization of modern data structures using BigInt for 64-bit integers \(e.g., database IDs, Twitter snowflakes\). The replacer function is the spec-compliant way to handle this, requiring manual conversion to string \(losing type info on parse\) or using a library that injects type tags.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:27:33.075939+00:00— report_created — created