Invalid numbers in JSON
JSON's number grammar is narrower than JavaScript's. Leading zeros, a leading plus, hex literals and a bare decimal point are all rejected.
Open the JSON formatterWhat the error looks like
Different engines word this differently. You may see any of these:
Why it happens
- JSON numbers allow an optional minus, digits, an optional fraction and an optional exponent. Nothing else.
- A leading zero such as 007 is invalid, which catches zero-padded identifiers and version numbers.
- A leading plus such as +1 is invalid, as is a hexadecimal literal such as 0x1F and a trailing decimal point such as 1. or a leading one such as .5.
Example
{
"id": 007,
"delta": +1,
"mask": 0x1F,
"ratio": .5
}
{
"id": 7,
"delta": 1,
"mask": 31,
"ratio": 0.5
}
How this tool reports it
The formatter reports each one with the correction it would make, and converts hexadecimal literals to their decimal value rather than dropping them.
Paste your JSON into the formatter to see the exact line and column, or use the validator if you only need to check it.
Worth knowing
- If a leading zero is significant, as it is in a postcode, an account number or a version segment, the value is not a number. Quote it as a string.
- JSON puts no limit on the size of a number, but most parsers read it into a double, so integers beyond 2^53 lose precision. Send those as strings. This tool preserves the literal exactly as written so you can see whether that has happened.