What valid JSON files are not valid YAML 1.1 files?

后端 未结 2 1386
死守一世寂寞
死守一世寂寞 2021-02-15 13:52

YAML 1.2 is (with one minor caveat regarding duplicate keys) a superset of JSON, so any valid JSON file is also a valid YAML file. However, the YAML 1.1 specification (which ha

2条回答
  •  生来不讨喜
    2021-02-15 14:28

    See here (specifically footnote 25). It says:

    The incompatibilities were as follows: JSON allows extended character sets like UTF-32 and had incompatible unicode character escape syntax relative to YAML; YAML required a space after separators like comma, equals, and colon while JSON does not. Some non-standard implementations of JSON extend the grammar to include Javascript's /*...*/ comments. Handling such edge cases may require light pre-processing of the JSON before parsing as in-line YAML

    See also https://metacpan.org/pod/JSON::XS#JSON-and-YAML

    Related
    What is the difference between YAML and JSON? When to prefer one over the other

提交回复
热议问题