Skip to content

unsafe-numbers

JSON / JSONCsuspiciousno fixdefault: off

Reports a number that a double-precision parser (JavaScript and most JSON libraries) cannot hold exactly: an integer beyond 2^53 - 1, a value that overflows to infinity, or one that underflows to zero or is subnormal.

JSON allows any number of digits, but most parsers read numbers as 64-bit floating point. A large integer such as an id then changes silently (12345678901234567890 becomes 12345678901234567000), and 1e999 becomes infinity, so the receiver sees a different value from the one that was written.

To fix, write the value as a string.

Reported
[9007199254740991, 9007199254740992, -12345678901234567890, 1e999, 1e-999, 5e-324, 0, 0.0e5, 1.5, 12345678901234567890.5]
json:
lint:
rules:
unsafe-numbers: warn # off (default), warn, error

Suppress one line with sudsy-disable-next-line unsafe-numbers in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
Biome nursery/noJsonUnsafeValues partial lone UTF-16 surrogates in strings are not reported