[Fwd: Re: YAML ain't a superset of JSON]

Oren Ben-Kiki <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <1244318281.4601.11.camel@nero>
On Sat, 2009-06-06 at 15:07 +0200, Jakob Voss wrote:
> 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).
> ...
> 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).

Well then, this makes YAML processors no different from other JSON
processors then. That is, technically speaking, a YAML processor is a
valid JSON processor as per RFC 4627.

> That's fine unless all you deal with is a subset of JSON with unique
> names in objects.

I would claim this is not a "subset" of JSON, this _is_ JSON. That is,
if some misguided soul serialized PHP "ordered hashes" into JSON objects
(and had a PHP implementation that safely de-serialized it), I would
claim they are working outside the bounds of the JSON spec.

So, all in all, I don't see this as an issue. It may be worth a note
somewhere though.

> BTW: Talking 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.

Hmmm. This is an excellent question. I believe the resolution for this
should be:

- The failsafe schema is unaffected, as it should be safely applicable
to every YAML document - not necessarily JSON-compatible ones.

- The JSON schema should be restricted to disallow non-scalar keys, as
you correctly pointed out.

- The core schema is unaffected, as it is the "simple" extension of the
JSON schema to include basic YAML features - such as complex keys.

Very nice catch!

Thanks,

    Oren Ben-Kiki


------------------------------------------------------------------------------
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.