Skip to content

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.

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
[2e308]
{
"value": "\ud83d"
}
[1e-400]
{
"id": 9007199254740992
}
[2.2250738585072009e-308]

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.