Formatting JSON without rewriting a large integer token
A formatter should change the layout of a JSON document and leave its numbers alone. This worksheet formats an integer just above the largest safe JavaScript integer and checks that every digit comes back.
Why large integers deserve a check
JSON itself puts no limit on the size of a number. Most software that reads JSON stores numbers as 64-bit floating-point values, which hold integers exactly only up to 9,007,199,254,740,992, which is 2 to the power 53. JavaScript names the largest integer below that threshold Number.MAX_SAFE_INTEGER, 9,007,199,254,740,991. Above it, neighboring integers can no longer all be represented. A formatter that parses and re-prints numbers would quietly change such values, and the altered document would still be valid JSON, so no error would appear to warn anyone. The test integer here, 9007199254740993, is just past that limit, so a rewrite would reveal itself.
The worksheet's two runs
The first run feeds {"id":9007199254740993} to the formatter with an indent of 2, which is the setting a person would use when reading the result. The result is the object over three lines, with the id on its own line indented by two spaces and the digits unchanged. The second run feeds the same token inside a loosely spaced document and uses an indent of 0, giving the compact form {"id":9007199254740993}. In both outputs the last digit is still 3. A parse-and-print approach in a double-precision language would have produced 9007199254740992 instead, one less than the input. Both numbers would then display as valid integers, which is why the difference can pass unnoticed unless you compare the digits.
How the formatter avoids rewriting
The implementation validates the syntax of the document and then lays out the original tokens. It does not turn the digits into a number and format that number again. Because the text of the token is copied as it was typed, no precision is lost, and the output of formatting is the same data in a new arrangement. The difference between the two runs is therefore whitespace only: the pretty version adds line breaks and indentation, and the compact version removes spaces. The reverse run, from loose spacing back to the compact form, is how the second control tests the formatter: the input has spaces around the colon and inside the braces, and none of them survive.
Choosing the indent
The indent input controls the layout. Zero produces the compact form with no spaces after colons or commas. A value such as 2 puts each property on its own line and indents nested content by two spaces per level, which is easier to read. Larger values simply widen the indentation. The choice affects only readability and file size, and every setting returns the same data. For a small object like this one, the pretty form takes three lines. For arrays, the same indent puts each element on its own line, so [1,2] becomes three lines with the elements indented. Some teams standardize on an indent of 2 for configuration and 0 for network payloads, which keeps reviews readable and transfers small.
Preserving a token is not the same as using it safely
The formatter keeps the digits. It cannot control what the next program does with them. If the document is loaded by JavaScript code with ordinary parsing, the value 9007199254740993 becomes 9007199254740992 before any of your logic sees it. Languages with arbitrary-precision integers, or with 64-bit integer types such as a signed 64-bit integer that reaches 9,223,372,036,854,775,807, will keep it. The risk is in the consumer, and the right defense is knowing what it does with large numbers. Reading the consumer's documentation or testing it with the sample id takes a minute and tells you whether an identifier will survive. If the consumer is a browser script, assume doubles unless it uses a big-integer type or a custom parser. JavaScript offers a BigInt type for exact integers, though ordinary JSON.parse does not produce it.
Identifiers are often safer as strings
Large integer fields are frequently identifiers, such as database keys or snowflake-style IDs used by social platforms. Because an identifier is a label and is never used in arithmetic, many APIs send it as a string, as in {"id":"9007199254740993"}, so that no parser can round it. Whether a field should be a number or a string is part of the API contract, and a formatter should not change it. Follow the documentation of the receiving system when choosing the representation, and keep the type consistent across every message. Changing a field from a number to a string, or the reverse, is a breaking change for any client that checks types, even though both forms pass a syntax check.
Checking a pipeline for silent changes
To test whether a pipeline rewrites numbers, send a document with a known awkward value through it, such as the id above, and compare the output with the input digit by digit. Include a decimal that ends in a zero, like 12.50, and an exponent form like 1e3, since these are also altered by serializers that print a number from its stored value. A twenty-digit integer such as 12345678901234567890 is another useful probe, because it exceeds even the signed 64-bit range and tells you whether the pipeline keeps text or converts. A pipeline that preserves all three is passing tokens through as text. One that changes them is converting through a numeric type.
What this check covers
The page separates syntax validation from numeric precision. A valid result means the document follows JSON grammar. It does not mean that every consumer can represent the number exactly, and it does not choose a safe numeric type for the field. The test integer is a single example chosen because it sits beyond the exact range of double-precision numbers.
Sizes of integers you may meet
It helps to know where common limits sit. A signed 32-bit integer reaches 2,147,483,647. A signed 64-bit integer reaches 9,223,372,036,854,775,807, about 9.2 quintillion. The exact range of a double is 2 to the power 53, about 9.007 quadrillion. Timestamps in milliseconds since 1970 are around 1.7 trillion today and fit comfortably, while nanosecond timestamps are around 1.7 quintillion and do not fit exactly in a double. Database keys generated by distributed systems often use the full 64 bits. Knowing which category your number falls into tells you whether string transport is needed. Counting digits is a quick screen: an integer with sixteen or more digits deserves a second look, and one with nineteen or more can exceed even the 64-bit signed limit.
Reproduce the checks
Pretty-print the document
Open the Json Validator Formatter and enter:
- JSON input
{"id":9007199254740993}- Indent
2
Expected output:
Valid
trueFormatted
{
"id": 9007199254740993
}The source digits are preserved exactly.
Compact the same token
Open the Json Validator Formatter and enter:
- JSON input
{ "id" : 9007199254740993 }- Indent
0
Expected output:
Valid
trueFormatted
{"id":9007199254740993}Whitespace changes while the numeric spelling remains intact.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08