noJsonUnsafeValues (JSON)
Language JSON (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.5.14 - Diagnostic Category:
lint/nursery/noJsonUnsafeValues - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
json/no-unsafe-values
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noJsonUnsafeValues": "error" } } }}Description
Section titled “Description”Disallow unsafe JSON values that may cause interoperability issues.
Some JSON values can break when parsed by different tools or languages as parser implementations & data types could differ.
For example, a very large number might become Infinity in JavaScript,
or a string with an incomplete Unicode pair might fail to decode properly.
The common unsafe values are:
- Lone surrogates in strings: Incomplete Unicode character pairs that can cause encoding/decoding failures
- Numbers that evaluate to Infinity: Values like
1e400that exceed JavaScript’s number range - Unintentional zeros: Very small numbers (e.g.,
1e-400) that silently evaluate to zero due to precision limitations - Unsafe integers: Numbers outside JavaScript’s safe integer range (
±2^53-1) that lose precision - Subnormal numbers: Very small floating point values that may be handled differently across systems
These issues can lead to data corruption, silent failures, or inconsistent behavior across different platforms and languages.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”{ "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]Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.