JSON numbers look innocent. They print cleanly, they sort, they round-trip through JSON.stringify() and back — until the day an identifier comes back from the API one digit short, and every request built on top of it quietly targets the wrong row. There is no exception, no warning, and no stack trace, because nothing went wrong from JavaScript's point of view. The number you received was parsed into exactly the value the language can represent, and the original digits simply never made it across.
This guide explains why any JSON integer above 2^53 changes value the moment JSON.parse() touches it, how to detect the damage, and what to do about it at every layer of the stack.
A bug that never throws
Start with the smallest possible reproduction. Below is a response body exactly as it arrives on the wire, followed by the same document after JavaScript parses it:
// Response body, byte for byte as sent by the server:
{"id": 9007199254740993, "plan": "pro"}
const parsed = JSON.parse('{"id": 9007199254740993, "plan": "pro"}');
console.log(parsed.id); // 9007199254740992
console.log(parsed.id === 9007199254740992); // true — and that is the problem
Nothing failed. The parser read the sixteen-digit token 9007199254740993, discovered that no floating-point value corresponds to it exactly, and snapped it to the nearest representable double: 9007199254740992. The tail digit was not truncated like a string slice — it was rounded, following rules that are perfectly deterministic once you know how the storage works. If your code later sends 9007199254740992 back to the server as an ID, the backend either finds no such row or, in the worst case, finds somebody else's.
How IEEE 754 doubles store integers
JavaScript has exactly one number type: the IEEE 754 double-precision float, known in the language specification as the Number type. Every number you parse, add or print is one of these. A double stores three parts:
- 1 sign bit — positive or negative.
- 11 exponent bits — the position of the binary point, covering magnitudes from roughly 1e-308 to 1e308.
- 52 fraction bits — the significant digits after the binary point.
The part that matters here is a trick: for numbers in the normal range, the mantissa always begins with an implicit leading 1 that is never stored. Those 52 stored bits plus the implicit bit give every double 53 significant bits of precision — and that is the entire budget an integer gets before it starts losing digits.
The 53-bit mantissa, in plain terms
Think of the mantissa as a 53-digit register. Every integer from 1 up to 2^53 − 1 fits in that register exactly, one value per slot, with no gaps. Above 2^53 the register can no longer hold consecutive integers, so the spacing between representable numbers widens:
- Between 2^53 and 2^54, only every 2nd integer exists.
- Between 2^54 and 2^55, only every 4th.
- Between 2^55 and 2^56, only every 8th — and so on, the gap doubling at each power of two.
When the engine is handed an integer that lands inside one of those gaps, it keeps the nearest representable neighbor. On an exact tie — the value sits precisely halfway between two representable numbers — IEEE 754 rounds to the neighbor whose mantissa ends in a zero bit, a rule known as "round half to even". You can watch the gaps open up in a console:
2 ** 53; // 9007199254740992
2 ** 53 + 1; // 9007199254740992 — snapped back down
2 ** 53 + 2; // 9007199254740994 — the next real integer
2 ** 53 === 2 ** 53 + 1; // true
That last line is the whole story in a single expression: two different integers compare equal because they were collapsed onto the same double before the comparison ever ran. The rounding is not random and not a bug in your code — it is the storage format doing exactly what its designers specified, applied to a value it was never meant to hold.
The safe range: Number.MAX_SAFE_INTEGER
The language draws the line explicitly. Number.MAX_SAFE_INTEGER is 2^53 − 1, or 9,007,199,254,740,991, and Number.MIN_SAFE_INTEGER is its negative. "Safe" has a precise meaning in the ECMAScript specification: an integer n is safe when it can be represented exactly and no other integer rounds to the same double. Both conditions matter. The value 2^53 itself is stored exactly, yet it is not safe, because 2^53 + 1 collapses onto it — you cannot reliably tell the two apart.
The built-in predicate tests exactly that property:
Number.isSafeInteger(9007199254740991); // true
Number.isSafeInteger(9007199254740992); // false
Number.isSafeInteger(1234567890123456789); // false
Keep in mind what Number.isSafeInteger() can and cannot do. It runs after parsing, so it can tell you that a value is unsafe, but it can never tell you what the original digits were. Detection at runtime is damage assessment, not recovery. The only place the full number still exists is the raw text of the response.
The table below shows what the parser actually hands back for inputs around and beyond the boundary. The parsed column is exactly what console.log prints after JSON.parse:
| Number on the wire | Value after JSON.parse | Represented exactly? | Safe integer? |
|---|---|---|---|
| 9007199254740991 (2^53 − 1) | 9007199254740991 | Yes | Yes |
| 9007199254740992 (2^53) | 9007199254740992 | Yes | No |
| 9007199254740993 | 9007199254740992 | No | No |
| 1234567890123456789 | 1234567890123456768 | No | No |
| 9223372036854775807 (int64 max) | 9223372036854776000 | No | No |
Two details in that table deserve attention. First, the corruption is invisible in ordinary use: 9007199254740992 looks like a perfectly plausible ID, with every digit accounted for. Second, the error grows with magnitude — one unit near 2^53, twenty-one units at 1234567890123456789, and by the int64 maximum the parsed value has drifted 193 away from the number on the wire.
The classic victim: long database IDs
Every backend language has a native 64-bit integer type, and every serious system eventually uses one: BIGSERIAL and BIGINT columns in PostgreSQL, long in Java and C#, int64 in Go and Rust. Distributed systems go further and mint IDs in application code — snowflake-style identifiers pack a timestamp, a machine ID and a sequence counter into a single unsigned 64-bit integer, which is why they carry eighteen or more digits and climb steadily toward the int64 ceiling.
JSON makes the situation worse by design, not by accident. The JSON specification defines a number as an abstract value with unlimited precision and a single numeric type — there is no int32, no int64, no distinction between an ID and a measurement. So a Java service holding a long emits it as a bare token by default, the token crosses the network perfectly intact, and the damage happens in the last inch: the moment a JavaScript client calls JSON.parse() on it.
The nastiest variant is collision. Two distinct 64-bit keys that differ only in their low bits can collapse onto the same double in the browser:
// Three different rows in the database:
JSON.parse('{"id": 9007199254740991}').id; // 9007199254740991
JSON.parse('{"id": 9007199254740992}').id; // 9007199254740992
JSON.parse('{"id": 9007199254740993}').id; // 9007199254740992 — collision!
// Distinct IDs, one value:
JSON.parse('{"id": 9007199254740992}').id ===
JSON.parse('{"id": 9007199254740993}').id; // true
Once corrupted IDs enter a cache, a client-side store, or a list of React keys, two different entities share one identity. Deduplication silently drops records, updates land on the wrong object, and the failures surface far away from the code that caused them — often days later, in a support ticket nobody can reproduce.
Detecting the damage
Compare the raw text against the parsed value
Because the corruption happens at parse time, the raw response text is your only ground truth. The quickest smoke test is to parse, re-stringify, and diff the result against the wire:
const raw = await res.text();
const reserialized = JSON.stringify(JSON.parse(raw));
// Heuristic, not proof: if any number token lost digits on parse,
// the two strings will disagree. Whitespace and key order also
// cause diffs, so inspect them before blaming precision:
console.log(raw.trim() === reserialized); // false means look closer
For a precise diagnosis, extract the number tokens from the raw text and test each one for safety. This works because the tokens are still strings at that point — full precision, untouched by the parser:
const tokens = raw.match(/-?\d+(\.\d+)?([eE][+-]?\d+)?/g) ?? [];
const unsafeInts = tokens.filter(t =>
/^-?\d+$/.test(t) && !Number.isSafeInteger(Number(t))
);
console.log(unsafeInts);
// e.g. ['9007199254740993', '1234567890123456789']
Every entry in that list is a number the browser has already rounded somewhere, the moment it parsed the document. If the response does not parse at all, that is a different failure mode entirely — see the guide on pinpointing JSON syntax errors by line and column for tracking those down.
The trailing 001 / 002 signature
Sequential IDs leave a recognizable fingerprint in logs once they cross the safe boundary. Consider a run of consecutive keys near 2^53: every odd value sits exactly halfway between two representable doubles, and ties round to the even neighbor. The result is that ...001 and ...002 both come back as ...002, then ...003 and ...004 both come back as ...004:
// A database assigns four consecutive IDs; the client parses them:
JSON.parse('9007199254740991'); // 9007199254740991 — last safe ID
JSON.parse('9007199254740992'); // 9007199254740992
JSON.parse('9007199254740993'); // 9007199254740992 — duplicate!
JSON.parse('9007199254740994'); // 9007199254740994
So when a support engineer reports that two orders share one ID, or your logs show identifiers whose final digits are always even above a certain size, you are almost certainly looking at double rounding rather than a backend bug. The pattern scales with magnitude: further up the range, IDs collapse in groups of four, then eight, then 256, and the surviving tails are all multiples of those steps.
Fixes that actually hold
Keep IDs as strings at the source
The durable fix costs nothing at the data layer and one line at the serialization layer: identifiers are not quantities, so do not encode them as JSON numbers. Most serialization frameworks support it out of the box — Jackson's ToStringSerializer in Java, string-writing number handling in .NET's System.Text.Json, a custom marshaler in Go. The payload becomes:
{"id": "9007199254740993", "plan": "pro"}
Strings pass through JSON.parse() byte for byte, sort correctly in most UI contexts, and cost a handful of bytes. Reserve JSON numbers for values you genuinely compute with — counts, amounts, coordinates. A useful rule of thumb: if you would never do arithmetic on it, it is a string, not a number. The same discipline applies to structured error payloads — when an API error carries the record key that failed, encoding it as a string inside a Problem Details response keeps it intact on every client, including browsers.
Parse numbers yourself when you cannot change the source
Sometimes the API belongs to a third party and the bare numbers are already on the wire. One crucial limitation first: the reviver callback of JSON.parse() cannot help you. The reviver runs after each token has already become a double — the low bits are gone before your function is invoked. What does work is guarding the raw text before the standard parser ever sees it:
// Quote bare integer literals of 16+ digits only where they appear
// as JSON values (after ':', ',' or '['), never inside strings:
const guarded = raw.replace(
/([:,\[]\s*)(-?\d{16,})\b/g,
'$1"$2"'
);
const doc = JSON.parse(guarded);
doc.id; // "9007199254740993" — every digit intact, now a string
This snippet is deliberately minimal; a production-grade version also needs to skip digits inside string literals and handle values at the top level and inside nested arrays. That is exactly why battle-tested libraries such as lossless-json exist — they implement a complete parser that preserves every number token verbatim, typically exposing oversized values as BigInt. And if you do adopt BigInt end to end, note that JSON.stringify() throws on BigInt values unless they define a toJSON() method, so serialization needs the same deliberate treatment that parsing did.
A word on BigInt: it solves the JavaScript side — exact integers of arbitrary size — but it is not a drop-in replacement for Number. There is no implicit conversion between BigInt and Number, arithmetic operators refuse mixed operands, and native JSON.stringify() rejects it outright. Adopting it is a deliberate type-system decision, not a patch you sprinkle over a broken endpoint.
Use a backend that speaks integers
It is worth remembering that Node.js shares the problem — it is the same double-precision runtime as the browser. If a Node middle tier parses an upstream payload and forwards it onward, the digits are already lost inside your own service, even if the final client is a language that could have handled them. The robust architecture keeps 64-bit integers in a layer that has real ones: PostgreSQL, Java, Go, Rust, or Python's arbitrary-precision int, and converts to strings at the JSON boundary. Anything earlier — parsing in the browser, patching regexes in a proxy — is mitigation, not a cure.
Time values deserve a special mention because they creep over the boundary from an unexpected direction. Millisecond Unix timestamps are still comfortably safe — the current epoch sits around 1.8 × 10^12 — but nanosecond timestamps and high-resolution performance counters reach 10^18 and beyond, deep into unsafe territory. If you are correlating log entries by nanosecond keys, the timestamp unit confusion guide covers the pairing problem of units and identifiers in detail. The lesson is the same: decide the unit and the encoding deliberately, before the format decides for you.
Why the JSON Inspector keeps number tokens verbatim
This site's JSON Inspector is built to be trustworthy precisely on this failure mode. It treats the document as text with structure rather than as a tree of doubles: number tokens are displayed exactly as they were written on the wire, so 9007199254740993 stays 9007199254740993 on screen, with no silent rounding between the input box and your eyes. Drilling into a value shows the original token, which makes the wire-versus-parsed discrepancy instantly visible instead of something you have to suspect and prove.
The same principle drives JSON Compare: when you diff two payloads, number differences are surfaced as written, so a payload containing ...0993 and one containing ...0992 are reported as different values rather than being equalized by rounding before the comparison runs. For ID-corruption investigations, that is exactly the behavior you want — the tool must not repeat the parser's mistake while you are busy diagnosing it.
A debugging checklist
When a value arrives "wrong" and you suspect precision, work through this list in order:
- Look at the wire, not the console. Log the raw response text. The console prints doubles, which is the damaged artifact, not the evidence.
- Count the significant digits. Any integer of 16 or more digits is beyond the safe range by definition. Count digits rather than estimating magnitudes.
- Run the token scan. Extract number literals from the raw text and check each with
Number.isSafeInteger()— the snippet above is ready to paste. - Check for the trailing pattern. Duplicated consecutive IDs, or identifiers whose last digits are restricted to even values or multiples of 4, 8 and higher powers of two, indicate tie-rounding at a specific magnitude.
- Confirm at the boundary. Parse the same raw text in a language with a real 64-bit integer type — Python is convenient for this. If the digits survive there and not in the browser, you have your answer.
- Fix the encoding, not the symptom. Resist the temptation to patch a parsed value with arithmetic after the fact. Repair the serialization so IDs travel as strings, then verify the whole path end to end.
- Re-test with adversarial fixtures. Keep the boundary values from the table above in your test suite. Any parser, client or proxy that silently rounds them is misconfigured and will corrupt production data eventually.
Test it yourself
Open the JSON Inspector, paste {"id": 9007199254740993}, and check the number token on screen against what a plain JSON.parse() reports in your browser console — the discrepancy is right there. Then load two versions of the same payload with a one-digit difference into JSON Compare and confirm the diff reports a real change rather than absorbing it. Both tools run entirely in your browser, so the payloads you paste — including anything carrying production IDs — never leave your machine.
Reproduce every example locally with the JSON Inspector or the matching tool on the workbench. Nothing you paste leaves your browser.