YAML ain't a superset of JSON

Jakob Voss <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
Hi,

The current  YAML WD (Version 1.2, 2009-04-26) defines a mapping as an
unordered association of unique keys to values (3.2.1., 3.2.1.1,
3.2.1.3). At the same time it is said that YAML can "be viewed as a
natural superset of JSON" (1.3). BUT the JSON specification RFC 4627
clearly states that "the names within an object SHOULD be unique" (2.2).
Therefore you can create a valid JSON string that is not a valid YAML
serialization that can be created a YAML Representation graph from. For
instance:

{ "foo": "bar", "foo": "doz" }

Obviously most JSON parsers ignore multiple same names in one object
with undefined behaviour (you can ignore all but the first, all but the
last, or all but a random entry or you can throw an error or warning).
That's fine unless all you deal with is a subset of JSON with unique
names in objects. YAML is a suberset of this subset of JSON - but it's
not a superset of JSON.

Can you please clarify this in the spec?

BTW: alking about subsets and subersets - is there an oficial name of
the subset of YAML that only allows scalars as mapping keys? The
failsafe schema explicitely does not place restrictions on the type of
keys. In contrast most use cases and implementations will only allow
scalar keys. I bet the situation will be similar to JSON where most
people just ignore the "SHOULD"-clause on object keys in the
specification - a situation that should be prevented by a good standard
specification.

Greetings,
Jakob Voss



------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.