Format JSON Without Losing Large Integer Precision

Test a large JSON ID, spot rounding in JavaScript, and keep the original digits when formatting API responses.

Recognize an ID that can be rounded

An order ID can be valid JSON and still change after a JavaScript application reads it. JavaScript Number safely represents every integer only between -9,007,199,254,740,991 and 9,007,199,254,740,991. Above that range, some distinct integers become the same numeric value.

Use the sample below as a precision check. A changed final digit is data loss, even if the result still passes JSON validation.

Original JSON: {"orderId":9007199254740993}
JSON.stringify(JSON.parse(original)):
{"orderId":9007199254740992}

Check the formatter with a known payload

Open the JSON formatter and replace the sample input with {"orderId":9007199254740993}. Choose Format JSON, then Minify. The output should retain 9007199254740993 in both cases.

This formatter preserves numeric tokens rather than converting them to JavaScript Number during formatting. Compare the output with the original response before sending it to another system. Formatting cannot recover digits that were already rounded upstream.

Choose an API representation deliberately

If an identifier is never used for arithmetic, consider a decimal string such as "9007199254740993" in your API contract. Coordinate the type change with consumers; changing a number to a string can break validation.

For calculations, use an appropriate integer or decimal implementation throughout the receiving application. Keeping digits in a formatted document does not ensure another parser will keep them.

Reference: MDN: Number.MAX_SAFE_INTEGER.