Report #58363
[gotcha] JSON.parse loses precision for integers > 53 bits and JSON.stringify throws on BigInt
Never pass BigInt through standard JSON serialization. For large integers \(IDs, timestamps\), serialize as strings with a type tag \(e.g., \`\{"id":"12345678901234567890"\}\`\) and revive using a \`reviver\` function that detects the tag and converts to BigInt. Use \`json-bigint\` library for automatic handling.
Journey Context:
JSON specification \(RFC 8259\) represents numbers as IEEE 754 binary64 doubles. JavaScript's \`JSON.parse\` inherently parses all numeric values into Number type, silently losing precision for integers exceeding \`Number.MAX\_SAFE\_INTEGER\` \(2^53 - 1\). This corrupts large database IDs \(Snowflake, Twitter\) or blockchain values without throwing errors. Additionally, \`JSON.stringify\` throws a TypeError when encountering BigInt values, as BigInt has no JSON representation in the spec. Developers often attempt replacer/reviver functions, but naive implementations fail to handle nested objects or arrays correctly. The robust pattern requires a serialization library \(e.g., \`json-bigint\`, \`devalue\`\) that converts BigInts to strings with metadata, or a manual schema-based approach ensuring large numbers are string-encoded at the API boundary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:27:07.549139+00:00— report_created — created