Report #47411
[gotcha] JSON.stringify throws TypeError when encountering BigInt values
Implement a custom replacer function: JSON.stringify\(obj, \(key, value\) => typeof value === 'bigint' ? value.toString\(\) : value\). Alternatively, use a serialization library that supports BigInt.
Journey Context:
BigInt was added to ECMAScript 2020 but the JSON specification predates it and doesn't define a serialization format for arbitrary-precision integers. JSON.stringify throws a TypeError when encountering BigInt, unlike other primitive types. This breaks serialization of modern data structures containing large integers \(e.g., database IDs, timestamps\). Developers often assume BigInt serializes to string or number automatically. The fix requires explicit replacer functions or pre-processing to convert BigInt to string. Alternatives like serializing to a custom format \{type: 'bigint', value: '123'\} work but break standard JSON consumers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:03:43.074844+00:00— report_created — created