Report #93270
[gotcha] JSON.stringify throws TypeError on BigInt values
Implement a replacer function that converts BigInt to string or number, or use a custom serialization library that supports BigInt.
Journey Context:
BigInt was added to JavaScript after JSON.stringify was standardized. The JSON spec does not support BigInt, so JSON.stringify has no default representation for it. Unlike \`undefined\` \(which is omitted in objects or converted to null in arrays\), BigInt causes an immediate TypeError: 'BigInt can't be serialized in JSON'. This is a serialization footgun: a single BigInt deep in an object tree crashes the entire serialization. The robust fix is to provide a replacer function \`\(key, value\) => typeof value === 'bigint' ? value.toString\(\) : value\` \(often with a suffix to indicate revival\), or to use a library like \`json-bigint\` that handles BigInt natively.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:08:26.567956+00:00— report_created — created