Report #85126
[gotcha] JSON.stringify throws TypeError when serializing objects containing BigInt values
Convert BigInt to String using .toString\(\) or wrap BigInt in an object with a toJSON method; alternatively use a replacer function: \(k, v\) => typeof v === 'bigint' ? v.toString\(\) : v
Journey Context:
Many developers assume BigInt behaves like Number for serialization. However, the JSON spec does not support BigInt, and TC39 explicitly mandated throwing rather than silent coercion to prevent data loss. Common mistakes include returning BigInt from API endpoints or storing BigInt in Redis/JSON databases without string conversion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:28:12.103202+00:00— report_created — created