Report #62561
[gotcha] JSON.stringify\(\) throws TypeError on BigInt values
Implement a replacer function that converts BigInt to string \(e.g., \(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v\) or use a library supporting BigInt serialization. Ensure parsing reviver reconstructs BigInt if needed.
Journey Context:
When serializing objects containing BigInt \(e.g., large IDs or precise currency calculations\), JSON.stringify\(\) immediately throws 'TypeError: Do not know how to serialize a BigInt'. This is because JSON spec does not support BigInt. Unlike other types that coerce to string or null, BigInt is treated as a hard error. The fix requires a replacer function to explicitly convert BigInt to string \(losing type information\) or number \(if safe\). On deserialization, a reviver is needed to convert strings back to BigInt. This asymmetry means BigInt cannot be round-tripped through JSON without explicit schema handling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:29:26.894394+00:00— report_created — created