Why Do Large Numbers Change When I Format JSON? (Precision Loss)
Your 19-digit ID ends in 000 after formatting JSON? Learn why JavaScript rounds integers above 9007199254740991, how to spot it and how to keep IDs exact.
The short answer
If a long number in your JSON (an order ID, a tweet ID, a 64-bit database key) comes out different after formatting, it is not a typo. The JSON Formatter reads your text with JavaScript's JSON.parse, and JavaScript stores numbers as 64-bit floating-point values. Integers bigger than 9,007,199,254,740,991 can't all be stored exactly, so they get rounded. The fix is to keep such values as strings in the JSON.
What you see
Paste this into the formatter:
{"orderId": 12345678901234567890, "price": 1.10, "qty": 1e3}
The formatted output is:
"orderId": 12345678901234567000
"price": 1.1
"qty": 1000
All three values look different from what you pasted. Only the first one is a real problem. We ran this exact input through JSON.parse and JSON.stringify in Node.js, which is what the formatter does, and got the output above.
Why it happens
JSON itself has no size limit on numbers. The text 12345678901234567890 is perfectly valid JSON. The limit comes from the program reading it.
JavaScript has one main number type, an IEEE 754 double-precision float. It has 53 bits for the digits of a number. That means:
- Every whole number from −9,007,199,254,740,991 to 9,007,199,254,740,991 is stored exactly. This limit is
Number.MAX_SAFE_INTEGER(2^53 − 1). - Above that, there are gaps. Some integers simply can't be represented, so the value is rounded to the nearest one that can.
You can see the gap with two numbers right next to each other:
| JSON input | After JSON.parse and re-format |
|---|---|
| 9007199254740991 | 9007199254740991 |
| 9007199254740992 | 9007199254740992 |
| 9007199254740993 | 9007199254740992 |
| 1234567890123456789 | 1234567890123456800 |
| 12345678901234567890 | 12345678901234567000 |
The third row is the clearest. 9007199254740993 becomes 9007199254740992 because the odd number in between doesn't exist as a double. The bigger the number, the bigger the gaps, which is why 19 and 20-digit IDs lose their last two or three digits.
The harmless changes: 1.10, 1e3 and 0.10
The formatter also prints some numbers differently even though the value is unchanged:
1.10becomes1.1(trailing zeros dropped)1e3becomes1000(exponent expanded)-0becomes0
These are equal values written another way. They matter only if something compares the raw text, such as a signature check or a hash over the JSON body. If you need the exact original text for that, don't re-format it before hashing.
How to tell if your data is affected
Common places this shows up:
- Twitter/X, Discord and similar IDs (snowflake IDs of 18 to 19 digits)
- 64-bit database primary keys exported by Java, Go, C# or Python services
- Card-like or account-like numbers stored as numbers instead of text
- Nanosecond timestamps, which have 19 digits
Millisecond Unix timestamps (13 digits) are safe. For more on those, see Unix timestamps: seconds vs milliseconds.
Check it yourself in the browser console
You can confirm the limit in any browser. Open developer tools (F12 on most desktop browsers), go to the Console tab and type:
JSON.parse('{"id": 12345678901234567890}').id
The console prints 12345678901234567000. Then try Number.isSafeInteger(9007199254740993), which returns false, while Number.isSafeInteger(9007199254740991) returns true. That function is a quick test for whether an integer will survive parsing.
How to fix it
1. Send big IDs as strings (best fix)
Change the producer so the value is quoted:
{"orderId": "12345678901234567890"}
Strings are never rounded. The formatter, browsers and every JSON library will keep all 20 characters. Many large APIs already do this and provide a separate string field (for example an id_str field next to a numeric id) for exactly this reason.
2. Parse with big-integer support
If you can't change the API, read it with a parser that keeps large integers:
- JavaScript: a library such as
json-bigintorlossless-json, which returns big values asBigIntor as their original text. - Python: the built-in
jsonmodule already keeps integers exact, because Python integers have no size limit. - Java, Go, C#: read the field into a 64-bit integer type (
long,int64) or a big-number type, not adouble.
Note that JSON.parse has no option that keeps precision for you. The reviver function receives the value after it has already been rounded.
3. Don't round-trip through a browser tool for production data
The formatter is a quick way to read and indent JSON. If the file contains 64-bit IDs and you plan to save the formatted output back, check the IDs first. Formatting and then copying the output over the original will permanently change those numbers in your copy.
What the formatter is still good for
Rounding only affects very large integers. For everything else the formatter is fine:
- It indents with 2 or 4 spaces and shows ✓ Valid JSON or the parser's error message.
- Minify & copy produces a compact single-line version.
- Strings, booleans,
null, nested objects and arrays are output exactly.
If the formatter shows an error instead of output, the problem is the JSON syntax, not number size. A common case is pasting an HTML error page; see Unexpected token '<' in JSON at position 0.
Quick checklist
- Number has 15 digits or fewer: safe.
- Number is above 9,007,199,254,740,991: will likely change after
JSON.parse. - Decimal looks different (1.10 to 1.1): same value, harmless unless you hash the text.
- Need exact IDs: store them as strings, or parse with big-integer support.
Frequently asked questions
Why did my JSON number end in 000 after formatting?
The formatter reads the JSON with JavaScript's JSON.parse, which stores every number as a 64-bit floating-point value. Integers above 9,007,199,254,740,991 cannot all be stored exactly, so they are rounded to the nearest value that can be, which often ends in zeros.
What is the largest integer JSON.parse keeps exactly?
Number.MAX_SAFE_INTEGER, which is 9,007,199,254,740,991 (2 to the power 53, minus 1). Any integer up to that size, positive or negative, survives a parse and re-format unchanged.
Is my original JSON file wrong?
Usually not. The JSON text itself can hold any number of digits. The change happens only when a program that uses 64-bit floats reads it. Keep the original text and fix the reading side, or send the value as a string.
How do I stop IDs from being rounded?
Send long IDs as strings, for example "id": "12345678901234567890". Strings are never rounded. If you cannot change the API, parse it with a library or language feature that supports big integers instead of plain JSON.parse.
Does formatting also change 1.10 to 1.1?
Yes. After parsing, 1.10 and 1.1 are the same number, so the formatter prints 1.1. Exponent forms such as 1e3 are printed as 1000. The value is equal, but the text is different.
Put this guide into practice with our free online tool — no signup required.
Open tool