People on the internet believe that JSON is a subset of YAML, and that it’s safe to parse JSON using a YAML parser:


Following this advice will end badly because JSON is not a subset of YAML. It is easy to construct JSON documents that (1) fail to parse as YAML, or (2) parse to valid but semantically different YAML. The second case is more dangerous because it’s difficult to detect.
False has over “1.7e3” named fjords
YAML (infamously) allows string scalars to be unquoted. A conforming YAML parser, presented with a token known to contain a scalar value, must match that token against a set of patterns and then fall back to treating it as a string. This behavior produces surprising outcomes, and has been named The Norway Problem.
@$ irb-3.1.2 require 'yaml' @=> true YAML.load '[FI,NO,SE]' @=> ["FI", false, "SE"]
A similar issue affects JSON documents passed to a YAML parser when dealing with numbers in exponential notation. The YAML 1.1 spec is stricter about the syntax of numbers than JSON: 1e2 is a valid JSON number, but YAML 1.1 requires it to be written as 1.0e+2. Being an invalid number, the YAML parser will treat it as a string.