valueSafety
Reports JSON values that are unsafe for data interchange.
✅ This rule is included in the json logical
preset.
JSON is widely used for data interchange between systems, but certain values can cause interoperability issues when transferred between different parsers and environments. This rule detects values that are unsafe for interchange, preventing data corruption, silent failures, or inconsistent behavior across different platforms and languages.
Unsafe Values
Section titled “Unsafe Values”This rule detects the following unsafe values:
- Lone surrogates in strings: Incomplete Unicode character pairs that can cause encoding/decoding failures
- Numbers that evaluate to Infinity: Values like
1e400
that 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
Examples
Section titled “Examples”[2e308]
{ "value": "\ud83d"}
[1e-400]
{ "id": 9007199254740992}
[2.2250738585072009e-308]
[123, 1234, 12345]
{ "emoji": "🔥"}
{ "emoji": "\ud83d\udd25"}
[0, 0.0, 0]
{ "id": 9007199254740991}
When Not To Use It
Section titled “When Not To Use It”If your project intentionally uses a mix of JSON levels of safety, such as systems that manually manipulate strings, this rule might not reflect your project’s needs. Consider refactoring to use safer value representations.
Further Reading
Section titled “Further Reading”- MDN: Number.MAX_SAFE_INTEGER
- MDN: Number.MIN_SAFE_INTEGER
- Wikipedia: UTF-16 Surrogates
- Wikipedia: Subnormal Numbers
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
json/no-unsafe-values
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.