Report #90762
[gotcha] JSON.stringify throws when encountering BigInt values
Provide a replacer function to convert BigInt to string representation \(e.g., \(key, value\) => typeof value === 'bigint' ? value.toString\(\) : value\) or use a library like json-bigint
Journey Context:
The ECMA-262 specification explicitly states that JSON.stringify must throw a TypeError when encountering a BigInt primitive or a BigInt object wrapper, as there is no standard JSON representation for arbitrary precision integers. This differs from how other types are handled \(e.g., undefined values in arrays become null, functions are omitted\). This creates a runtime crash in logging, serialization, or API request preparation when data contains BigInt values \(common for database IDs or blockchain values\). The standard workaround is to pass a replacer function that converts BigInt to string, or to use specialized libraries that encode BigInt as a custom JSON object format. Note that parsing such values back requires a corresponding reviver.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:56:24.502381+00:00— report_created — created