Skip to content

noJsonUnsafeValues (JSON)

Language JSON (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noJsonUnsafeValues": "error"
}
}
}
}

Disallow unsafe JSON values that may cause interoperability issues.

JSON parsers in different languages can use different number and Unicode representations. A value accepted by one parser may lose information or fail in another.

The rule reports:

  • lone UTF-16 surrogates, which are incomplete halves of an encoded Unicode character;
  • numbers outside JavaScript’s finite range, such as 1e400;
  • tiny nonzero numbers, such as 1e-400, that become zero because of limited precision;
  • integers outside JavaScript’s safe range (-(2^53 - 1) through 2^53 - 1), which lose precision;
  • subnormal numbers, which are extremely small floating-point values that systems may handle differently.

These values can cause data loss or inconsistent behavior when JSON moves between systems.

{
"invalid1": 2e308
}
code-block.json:2:15 lint/nursery/noJsonUnsafeValues ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ The number will evaluate to Infinity.

1 │ {
> 2 │ "invalid1": 2e308
│ ^^^^^
3 │ }
4 │

ℹ Certain values can cause interoperability issues between different parsers and environments. Replace this value with a safe alternative.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

{
"invalid2": -2e308
}
code-block.json:2:15 lint/nursery/noJsonUnsafeValues ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ The number will evaluate to Infinity.

1 │ {
> 2 │ "invalid2": -2e308
│ ^^^^^^
3 │ }
4 │

ℹ Certain values can cause interoperability issues between different parsers and environments. Replace this value with a safe alternative.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

{
"invalid3": "\ud83d"
}
code-block.json:2:15 lint/nursery/noJsonUnsafeValues ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Lone surrogate found.

1 │ {
> 2 │ "invalid3": "\ud83d"
│ ^^^^^^^^
3 │ }
4 │

ℹ Certain values can cause interoperability issues between different parsers and environments. Replace this value with a safe alternative.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

{
"invalid4": 1e-400
}
code-block.json:2:15 lint/nursery/noJsonUnsafeValues ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ The number will evaluate to zero.

1 │ {
> 2 │ "invalid4": 1e-400
│ ^^^^^^
3 │ }
4 │

ℹ Certain values can cause interoperability issues between different parsers and environments. Replace this value with a safe alternative.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

{
"invalid5": 9007199254740992
}
code-block.json:2:15 lint/nursery/noJsonUnsafeValues ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ The integer is outside the safe integer range.

1 │ {
> 2 │ "invalid5": 9007199254740992
│ ^^^^^^^^^^^^^^^^
3 │ }
4 │

ℹ Certain values can cause interoperability issues between different parsers and environments. Replace this value with a safe alternative.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

{
"invalid6": 2.2250738585072009e-308
}
code-block.json:2:15 lint/nursery/noJsonUnsafeValues ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Unexpected subnormal number found, which may cause interoperability issues.

1 │ {
> 2 │ "invalid6": 2.2250738585072009e-308
│ ^^^^^^^^^^^^^^^^^^^^^^^
3 │ }
4 │

ℹ Certain values can cause interoperability issues between different parsers and environments. Replace this value with a safe alternative.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

[
123,
1234,
12345, // Regular numbers within safe range
"🔥", // Properly formed Unicode character (fire emoji)
"\ud83d\udd25", // Same character with proper surrogate pair
0.00000,
0e0000000,
0.00000e0000 // Zero represented in different valid ways
]