Here is a bug that throws no error, passes most tests, and quietly corrupts data:
const text = '{"id": 1849302746519283746, "name": "Emily"}' JSON.parse(text).id // 1849302746519283700 The last three digits changed from 746 to 700. No exception, no warning. If that id is a tweet, a Discord message, an order or a database row, your code now points at a record that does not exist, or worse, at someone else's.
I ran into this while building a JSON formatter, so I tested exactly where it happens and what actually fixes it. Every snippet below was run in Node.js 24 or Python 3.13.
Why it happens
JSON itself has no limit on number size. JavaScript does: every number is a 64-bit float, which can only represent integers exactly up to 2^53 - 1.
Number.MAX_SAFE_INTEGER // 9007199254740991 2 ** 53 + 1 // 9007199254740992 (not ...993!) 9007199254740993 === 9007199254740992 // true Above that limit, JSON.parse picks the nearest number it can store. A 19-digit ID is far above it.
The same happens with response.json() in fetch, because it uses the same parser:
const res = await fetch('/api/order') // body: {"id": 1849302746519283746} const data = await res.json() data.id // 1849302746519283700 Long decimals lose digits too: 0.1234567890123456789 comes back as 0.12345678901234568.
Where these numbers come from
- Snowflake IDs: Twitter/X, Discord, Instagram and many internal systems generate 64-bit IDs. That is why the Twitter API added an
id_strfield and the Discord API sends IDs as strings. - Database keys: a PostgreSQL
bigintgoes up to 9,223,372,036,854,775,807, about a thousand times the safe limit. - Money and science: long decimals in prices, coordinates or measurements.
Other languages are often fine. Python keeps big integers exact:
import json json.loads('{"id": 1849302746519283746}')["id"] # 1849302746519283746 So a Python backend can send correct JSON that only breaks when it reaches JavaScript, which makes the bug hard to spot.
Fix 1: send big IDs as strings (best)
If you control the API, this is the simplest and most robust fix:
{ "id": "1849302746519283746", "name": "Emily" } IDs are labels, not quantities. You never add two order IDs, so a string loses nothing.
Fix 2: read the original text with context.source
Modern JavaScript lets a JSON.parse reviver see the exact source text of each value:
const data = JSON.parse(text, (key, value, context) => key === 'id' ? BigInt(context.source) : value ) data.id // 1849302746519283746n (a BigInt, every digit kept) This works in Node.js 22 and later (I tested on Node 24) and in recent Chrome and Firefox. Check browser support before you rely on it in front-end code.
Fix 3: write it back with JSON.rawJSON
BigInt has a catch: JSON.stringify refuses it.
JSON.stringify({ id: 10n }) // TypeError: Do not know how to serialize a BigInt The companion feature JSON.rawJSON writes a number exactly as you give it:
JSON.stringify({ ...data, id: JSON.rawJSON(data.id.toString()) }) // {"id":1849302746519283746,"name":"Emily"} Fix 4: in Python, decimals need parse_float
Python's integers are safe, but floats are not:
from decimal import Decimal json.loads('{"price": 0.1234567890123456789}', parse_float=Decimal)["price"] # Decimal('0.1234567890123456789') How to check your own data
A quick test: run your JSON through JSON.parse and JSON.stringify and compare. If any number changed, you have the problem. Look for integers with 16 or more digits.
If you just want to look at or clean up such JSON without writing code, the JSON Formatter I built keeps large numbers exactly as written (it says how many it protected), and the JSON Parser warns about every integer that is too large for JavaScript. Both run entirely in the browser.
Summary
| Situation | What to do |
|---|---|
| You control the API | Send IDs as strings |
| You must read numeric IDs in JS | JSON.parse reviver with context.source and BigInt |
| You must write them back | JSON.rawJSON |
| Long decimals in Python | json.loads(..., parse_float=Decimal) |
The scary part of this bug is the silence. If your app handles IDs from Twitter, Discord, a snowflake generator or a bigint column, it is worth checking today.
Have you been bitten by this one? I'd like to hear how you found it.