Large JSON numbers: preserve 64-bit IDs without silent rounding
· 4 min read · By Amir Badi
You open a JSON export, format it and save it. It still parses. But a 20-digit customer ID now ends in different digits.
You get no syntax error, because JSON allows that number. The program reading it uses a numeric type that can't hold it exactly. In JavaScript this bites database IDs, event identifiers and other big integers.
GigaJSON shows you when it happens. The workspace displays a precision notice, keeps the original source in its saved copy until you agree to rounding, and asks before anything writes rounded values. The warning doesn't make JavaScript numbers exact, though, so you still need to know where the limit sits.


Valid JSON can outgrow the reader
This is valid JSON:
{"id": 12345678901234567890, "status": "pending"}
Run this JavaScript:
const text = '{"id":12345678901234567890}';
const parsed = JSON.parse(text);
console.log(JSON.stringify(parsed));
// {"id":12345678901234567000}
JSON.parse changed the value. JSON.stringify(parsed, null, 2) adds indentation afterwards, and the lost digits stay lost.
JavaScript's largest safe integer is 9007199254740991 (2^53 - 1). Above it, JavaScript can still store some integers, but neighbouring integers start to share a value. JavaScript numbers go much higher than this; it's the point where integers stop being exact. MDN: Number.MAX_SAFE_INTEGER
The JSON specification lets implementations limit the range and precision of numbers. It names this same integer range as the one where common implementations agree exactly. So a validator can tell you a number is valid JSON, and can't promise that every reader keeps it intact. RFC 8259, numbers
Put identifiers in strings
A customer ID names something; you'll rarely do arithmetic on it. Write it as a string and every ordinary JSON reader keeps the digits:
{"id": "12345678901234567890", "status": "pending"}
Strings also keep leading zeros that matter, such as "000042". Whoever produces the API should make this choice and stick to it. Once a consumer has lost the digits, fixing the consumer comes too late.
Change the schema with it. If an API switches id from a number to a string, update the schema, the client types and the tests together, because downstream code will notice.
BigInt helps only with exact input
JavaScript can hold a large integer as a BigInt, provided you give it the exact digits:
const original = "12345678901234567890";
const exact = BigInt(original);
console.log(exact.toString());
// 12345678901234567890
const rounded = JSON.parse('{"id":12345678901234567890}').id;
console.log(BigInt(rounded).toString() === original);
// false
The second BigInt converts its input correctly. Its input was already wrong. Wrapping BigInt around a value that came out of ordinary parsing won't bring the digits back.
Writing it out is another catch: plain JSON.stringify doesn't accept bare BigInt values. MDN's BigInt documentation covers this. If the receiving API expects a string ID, write the string yourself:
const id = BigInt("12345678901234567890");
console.log(JSON.stringify({ id: id.toString() }));
// {"id":"12345678901234567890"}
If the receiver insists on an unquoted large number, use a parser and serializer that keep numeric tokens or arbitrary-precision values from start to finish. GigaJSON's parsed editor doesn't do that.
What GigaJSON keeps, and what it shows
The workspace holds two things: the stored source, and the parsed values that the views use.
When GigaJSON finds a number it can't show exactly, it opens the document with a notice that gives the count and an example. The stored source keeps the original digits until you agree to rounding. The tree, queries and other views use JavaScript numbers, so don't copy a rounded ID off the screen and assume it's exact.
On larger documents the precision check runs in the background. An edit, export or share that needs your decision waits for it, and the app shows Checking the numbers… while it does. Opening stays fast, and a quick click can't skip the check.


Before an edit or export writes rounded values, GigaJSON asks and shows what the example number will turn into. Cancel drops the pending action. Continue accepts rounding for that document, and the export that follows loses the digits.
JSON Lines files opened in the workspace get the same protection. The individual tool pages and the extension viewer tell you when output is rounded, but they don't have the workspace's storage or its consent step.
A safer way to handle numeric IDs
- Keep the original export. Don't rely on browser storage as your only copy.
- Check for a precision notice before you edit or copy values. A valid document can still hold numbers the parser rounded.
- If exact IDs matter, cancel the rounding. Ask the source system for an export that writes IDs as strings.
- Test with an ID you know. Put the full digits in a fixture and compare them as text, never as JavaScript numbers.
To convert a file you already have, use a parser that reads integer tokens exactly, and turn them into strings before JavaScript ever sees them. Python's standard JSON parser keeps integers exact, so for this small example it does the job:
import json
text = '{"id":12345678901234567890,"status":"pending"}'
data = json.loads(text)
data["id"] = str(data["id"])
print(json.dumps(data))
# {"id": "12345678901234567890", "status": "pending"}
That converts one field you know about. It won't handle exact decimals in general, and it can't guess which fields in an unknown document are IDs. For nested records, list the fields you mean to convert and check the output against the receiving schema. Python JSON decoder documentation
Open a sample in GigaJSON to see the notice before you try real data. If you're about to compare two exports, read the JSON diff guide as well: two rounded values that look equal don't prove the original IDs matched.