Runs locally
DEVDESK / GUIDES

JSON large integer precision: find and prevent lost digits

An order ID changes its final digit, yet JSON validation passes. Compare the raw response with the parsed value first: valid syntax and exact numeric representation are separate checks. This reproducible example helps locate the change.

Open tool: JSON formatter

1. Reproduce from the original text

This JavaScript example parses a JSON string. Its id becomes 9007199254740992 instead of the original 9007199254740993. Formatting the parsed result cannot recover the lost digit.

const raw = '{"id":9007199254740993}';
const parsed = JSON.parse(raw);
console.log(parsed.id); // 9007199254740992
console.log(JSON.stringify(parsed));
// {"id":9007199254740992}

2. Separate number representation from JSON syntax

JavaScript Number has a maximum safe integer of 9007199254740991, or 2 to the power of 53 minus 1. Beyond the safe range, not every integer can be represented and distinguished exactly. This does not mean every larger value is rounded.

JSON text can contain such a number. The issue is how a consumer parses and processes it. DevDesk formatting and minification preserve the original number text, which helps inspect raw responses; the tool does not change numeric types in other systems.

3. Find the first point where the digits change

Do not compare only objects already parsed in the console. Save the raw response text, compare it with the original identifier at the data source, then inspect parsing and output separately.

  • Paste the raw response into the JSON tool and check its final digits after formatting.
  • Use Text diff to compare the original response with JSON emitted by the application.
  • If the raw response is already wrong, inspect server serialization and the upstream data source.
  • If only the parsed value is wrong, look for Number, parseInt or default JSON.parse conversion.

4. Use strings for identifiers; choose arithmetic deliberately

For an order, user or record identifier, define a string field in the API contract and produce it from an exact source before serialization. Adding quotes around an already rounded Number preserves the wrong result.

For integer arithmetic, construct a BigInt from the complete string. Plain JSON.stringify does not directly serialize BigInt; agree on strings or another explicit wire representation with the receiving system.

const payload = { id: "9007199254740993" };
const text = JSON.stringify(payload);
const received = JSON.parse(text);
console.log(received.id); // "9007199254740993"
const exactInteger = BigInt(received.id);
console.log(exactInteger.toString()); // "9007199254740993"

5. Check each conversion you actually use

Recheck field types in clients, logs, exports and storage. A formatter that preserves raw JSON does not make every transformation lossless: this site’s YAML ↔ JSON converter rejects integers outside the safe range instead of silently producing rounded values.

Verify a normal integer, 9007199254740991 and 9007199254740993. Check types, text and application behavior. A fix is complete when the result matches the API contract.

Try it with these tools