7 ms·
YAML 1.2.2 still isn't a superset of JSON, because it requires all keys to be unique: > The content of a mapping node is an unordered set of key/value node pai
by n2d4 2y ago
YAML 1.2.2 still isn't a superset of JSON, because it requires all keys to be unique:
> The content of a mapping node is an unordered set of key/value node pairs, with the restriction that each of the keys is unique
- lifthrasiir 2y agoWhile JSON doesn't prevent duplicate keys per se, it doesn't fully specify its semantics anyway and only states that duplicate keys are less "interoperable". And there is an explicit profile of JSON with this requirement (I-JSON [1]), so YAML 1.2.2 can be said to be a superset of some version of JSON. [1] https://datatracker.ietf.org/doc/html/rfc7493 https://datatracker.ietf.org/doc/html/rfc7493
- n2d4 2y ago"X is a superset of some subset of Y" is a weak statement. This is not about semantics, it's about grammar. While it's fair to say that JSON "usually" is valid YAML, it's still good to be strict about it, because the existence of a single counterexample can be used maliciously.
- lifthrasiir 2y agoAgreed, though it is more like "X is a superset of some common but not de jure interpretation of Y". The real culprit is the ambiguity of Y...
- seba_dos1 2y agoA JSON implementation that rejects non-unique keys is a valid JSON implementation, so a valid YAML 1.2 implementation is still a valid JSON implementation.
- kazinator 2y agoSome things in the world of JSON depend on order, too. There is a Microsoft way of indicating the type of an object using a key that must be first in the JSON syntax.
- seba_dos1 2y agoSame situation as above - a JSON parser that ignores order is a valid JSON implementation.
- kazinator 2y agoAnd such a parser could work with that convention. However, if its complementary formatter printed the objects such that that type field doesn't appear first, it wouldn't be correctly implementing the specification.