Checking scientific-notation spelling during JSON formatting
1e3 and 1000 name the same number and are spelled differently. This worksheet formats each one and shows that the formatter returns the spelling it was given.
The grammar for numbers in JSON
A JSON number has an optional minus sign, an integer part, an optional fraction and an optional exponent. The exponent is the letter e or E, an optional plus or minus sign, and one or more digits. So 1e3, 1E3, 1e+3 and 1000 all conform, and so do 2.5e-3 and 0.0025. Several things that other languages accept are not allowed: a leading plus sign, a leading zero before more digits as in 01, a bare decimal point as in .5, and the words NaN and Infinity. The formatter checks these rules, and then it lays out the tokens that passed the check. A hexadecimal literal such as 0x10 and a number with a trailing decimal point, as in 5., fail for the same reason: neither fits the grammar.
Exponent and decimal side by side
The first control is {"value":1e3}. The second is {"value":1000}. Both are valid, and they describe the same quantity, one thousand. The compact outputs are {"value":1e3} and {"value":1000}, each exactly as typed. A formatter that parsed each number and printed it back would give the same text for both, since most languages print one thousand as 1000. This formatter does not do that. It treats the number as a token and only moves whitespace around, so the two outputs differ in spelling just as the two inputs did. You can verify this by placing the two outputs in a text comparison tool, which will flag the value line as changed even though a calculator would give one thousand for both.
Why spelling matters even when value does not
Spelling carries information that the value alone discards. A writer who typed 1e3 may have been signaling a measurement in scientific notation, and one who typed 1000 an exact count. A value written as 1.50 shows two decimal places, which a number type cannot hold on to. Prices, measurements reported to a stated precision and version-like values all lean on such trailing digits, and the precision a writer signals with them is lost the moment the token is turned into a float. Text comparison, hashing and digital signatures all operate on the characters, so changing 1e3 to 1000 would alter a document's hash even though no reader would see a difference in meaning. Preserving the token keeps the document byte-for-byte as faithful as the layout change allows.
More forms of the same value
One thousand can be written as 1e3, 1E3, 1e+3, 1.0e3, 10e2 and 1000, all valid. A small number such as 0.0025 can be written as 2.5e-3 or 25e-4. The formatter returns each exactly as it receives it. Case, sign and number of digits stay unchanged. This matters when different systems have standardized on different conventions, for example one that always writes exponents in lowercase with no plus sign, since a formatter that normalized them would hide a difference that a conformance check might be looking for. A test suite for a JSON parser, for example, depends on exactly these variants being passed through untouched so that each one reaches the parser under test.
What consumers do with the token
When a program reads the token, it converts the text into its own numeric type, and from that point the spelling is gone. A double-precision float stores 1e3 and 1000 as the identical bit pattern. A decimal type may keep more digits or the scale, and an integer type may reject the exponent form altogether, since some libraries refuse to read 1e3 as an integer. Whether a given consumer accepts an exponent for a field that should hold a whole number is a question for its documentation. Testing with a sample value such as 1e3 in that field takes a minute and shows whether the consumer reads it, rejects it or converts it to a float with a trailing .0.
Formatted is not canonical
Two documents that mean the same thing can still format to different text. They can differ in number spelling, in escape spelling inside strings, such as backslash u00e9 versus the character itself, and in property order. For that reason the formatted output is not a canonical byte representation for comparison or signing. If you need one, the rules must come from the consuming format. RFC 8785 specifies a canonical form for JSON in which numbers are printed by a defined algorithm, so 1e3 would become 1000, and it also sorts properties.
Spotting and fixing invalid exponents
Typical mistakes are a missing exponent digit, as in 1e, a space inside the number, as in 1 e3, a leading plus sign, and a comma used as the decimal mark, as in 1,5e3. Each fails the syntax check. The fix is to rewrite the token to match the grammar. A decimal comma needs to become a decimal point, and a thousands separator has to be removed, since JSON numbers carry no grouping characters. Retest after each change to see which edit cleared the error. Numbers pasted from a spreadsheet in a locale that uses a decimal comma, such as 2,5e3, are a frequent source of this failure, and the pasted text often passes unnoticed until the formatter flags it.
Token preservation in larger files
The two controls verify that the formatter preserves each valid token as written. They do not say which spelling you should use, and they do not test a document with many numbers. In a larger file the same preservation applies to every token, so a column of values in mixed styles would come back in the same mixed styles. For readability, plain decimal notation suits small ranges and exponent notation suits very large or very small magnitudes. Agree on a convention with your consumers and keep to it. Document it in the interface description, with one example of each form the field may take, so that a new producer does not guess.
Very large and very small magnitudes
Exponent notation earns its place at the extremes. The speed of light is about 2.998e8 meters per second, the mass of a hydrogen atom is about 1.67e-27 kilograms, and a population count in the billions reads more briefly as 7.9e9 than as a ten-digit run. Writing those magnitudes in plain decimal form invites miscounted zeros. Scientific data files, sensor logs and numerical results from simulations often use exponents for that reason. The formatter keeps whichever spelling the producer chose, so a long-running archive of measurements can be reformatted for reading without disturbing a single digit of the stored numbers.
Reproduce the checks
Exponent token
Open the Json Validator Formatter and enter:
- JSON input
{"value":1e3}- Indent
0
Expected output:
Valid
trueFormatted
{"value":1e3}The exponent is retained.
Decimal token
Open the Json Validator Formatter and enter:
- JSON input
{"value":1000}- Indent
0
Expected output:
Valid
trueFormatted
{"value":1000}This original spelling is retained as well.
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