Large IDs in JSON Lose Precision in JavaScript
9007199254740993 becomes ...992 after JSON.parse: why, and how APIs avoid it.
By the TurantTools Dev team · Updated October 27, 2026 · 3 min read
JavaScript numbers are 64-bit floats, exact only up to 2^53 − 1 (9,007,199,254,740,991). Larger integers, common as database IDs or Twitter/X-style snowflake IDs, silently change when parsed.
| Value | |
|---|---|
| ID in the JSON | 9007199254740993 |
| After JSON.parse in JavaScript | 9007199254740992 |
| Bits needed | 54 |
The last digit changed, and no error was raised.
Fixes
- Send large IDs as strings in JSON:
{"id": "9007199254740993"}. Many APIs do exactly this. - If you must read numbers, use a parser that supports BigInt, or a reviver with the raw text where available.
- Money is safer as integer minor units (cents) or a decimal string, never a float.