JSON number precision: why big ids lose digits

25 NOVEMBER 2026 · 7 MIN READ

A JSON number is a double, not digits. Above 2^53 consecutive integers stop existing, and the rewrite happens during parsing — before a formatter, validator or converter can show you anything.

RFC 8259 says almost nothing about numbers: it defines the syntax and then hands the semantics to "an IEEE 754 double", noting that implementations may vary. That one sentence is responsible for a steady stream of wrong ids, corrupt totals and invoices that differ by a cent. The syntax is fine. The value underneath it is not what you typed.

Before and after a parse

The same document, written and read back
in  {"id":12345678901234567890,"edge":9007199254740993,"neg":-0,"dec":1.0,"huge":1e500,"safe":9007199254740991}
out {"id":12345678901234567000,"edge":9007199254740992,"neg":0,"dec":1,"huge":null,"safe":9007199254740991}
The workbench formatting a document: the raw input holds 12345678901234567890, 9007199254740991 and 9007199254740993, the output shows the first and third rewritten, and the status bar reports two integers beyond 2^53 that lose precision
The same three numbers in the workbench, before and after one parse

Nothing was rejected. The document is valid JSON on both sides of that arrow. A double carries 53 bits of mantissa, so integers are exact only up to 9007199254740991 — Number.MAX_SAFE_INTEGER in JavaScript, 2^53 - 1. Past that point the representable values are further apart than 1, and the reader snaps your input to the nearest one it can hold.

Field by field

WrittenYou getWhy
1234567890123456789012345678901234567000rounded to the nearest representable double; the last three digits were never stored
90071992547409939007199254740992one past MAX_SAFE_INTEGER, where only even integers exist
-00negative zero survives in the hardware but JSON.stringify prints it without the sign
1.01JSON has no float/int distinction, so the formatting that told them apart is gone
1e500nullit parses to Infinity, and infinity has no JSON spelling, so serialisation replaces it
1e211e+21exact, only re-spelled — the printer switches to exponential form at 21 digits
0.10.1looks safe because printers round-trip short decimals; arithmetic on it is not: 0.1 + 0.2 is 0.30000000000000004

Which fields belong in quotes

  • ▸Distributed ids. Snowflake, Discord, Twitter/X and most ULID-adjacent schemes hand out 18–19 digit values, which is exactly the range where doubles start lying.
  • ▸Nanosecond and microsecond timestamps. Epoch nanoseconds passed 2^53 in 2011 and are now around 1.7e18.
  • ▸Anything with a leading zero. A zip code, an extension, a bank account segment. Precision is not even the issue; the zero is simply not part of a number.
  • ▸Version-like values. 1.10 and 1.1 are the same number and different versions.
  • ▸Barcodes and card numbers. EAN-13 fits inside the safe range but is still an identifier with a check digit computed over the digits, not the value.
  • ▸Fixed-point money. Either use strings or integer minor units, because binary floating point cannot represent 0.05 exactly.

Where the damage can be undone

It cannot be undone after parsing, in this tool or any other that uses JSON.parse. Every module here — tree view, validator, schema inference, converters, diff — reads the parsed value, so by the time you see a tree the tail is already gone. That is worth stating plainly, because the usual hope is that some display mode will show the original text. The one place a long digit string does survive is CSV import: a cell only becomes a number when the result stays inside ±2^53, so 12345678901234567890 is left as text — while 007 is comfortably inside that range and becomes 7.

Fixing it upstream

  1. 01 Serialise identifiers as strings at the producer. In Python that means json.dumps(obj, default=str) for ids you know about; in JavaScript a Map of BigInt fields that you convert explicitly; in Go a string tag or a custom marshaler.
  2. 02 Declare them as strings in the schema, so the mistake is caught rather than shipped. { "type": "string", "pattern": "^[0-9]+$" } costs nothing and documents intent.
  3. 03 If you do not control the producer, parse with a big-number-aware reader before it reaches a browser — json-bigint or lossless-json in JavaScript, json.loads(..., parse_int=Decimal) in Python — and keep the digits as text from that point on.
  4. 04 When the payload is already on disk and only a handful of fields matter, edit the text rather than the value: quote the digits first with sed or a PowerShell replace, then paste the result here. Once it has been through a JSON parser, the original characters are not recoverable.
  5. 05 JSON.stringify refuses a BigInt outright with Do not know how to serialize a BigInt. That error is a gift: it fails loudly instead of silently rounding, which is why 9007199254740993n is worth using when you have the choice.

Catching drift you already have

Two exports that should differ only in ordering will look identical if both lost the same digits, and the comparator cannot tell you why — it compares values, not text. When an id mismatch is suspected, diff the raw payloads as plain text before parsing them, then use the validator to confirm the document is at least well formed. If a field must be text, infer a schema from a known-good file and check the suspect file against it: an id that came back as a number is a type error, and type errors are the one thing inference does surface. The formatter is still useful at the end of that chain, because seeing 12345678901234567000 in the tree is the fastest proof that the digits are already gone.

NOTE The expensive case is a document that parses cleanly. A syntax error stops the pipeline; a rounded identifier flows through to a database write and turns up weeks later as a support ticket. Treat any unquoted numeric id in a JSON payload as a bug you have not found yet.

TOOL MATRIX

Tools for this guide

Keyboard shortcuts
FORMATTING
Format input Ctrl/⌘ + Enter
Toggle auto-format Ctrl/⌘ + Shift + A
CLIPBOARD & FILES
Copy output Ctrl/⌘ + K
Open JSON file Ctrl/⌘ + O
Download output Ctrl/⌘ + S
Save snippet Ctrl/⌘ + Shift + N
MODULES
Open find & replace Ctrl/⌘ + Shift + F
Lock / unlock output Ctrl/⌘ + Shift + L
Show this dialog Ctrl/⌘ + /
Local history
Save snippet
Erase local data

Nothing is stored in this browser yet.

Removes the saved draft, history, snippets and formatting options for this site. Documents you typed stay in the editor until the page reloads.