Re: JSON compatiiblity of YAML

Oren Ben-Kiki <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <1253333301.32004.92.camel@nero>
On Sat, 2009-09-19 at 12:27 +0900, Osamu TAKEUCHI wrote:
> Hi all,
> 
> The specification has the next statement in section 1.3.
> 
> > every JSON file is also a valid YAML file. 
> 
> However, ... I learned the following.
> 
> - JSON defines that the keys in a mapping node SHOULD be unique 
>   while YAML requires they MUST.
> - So, a YAML parser is a JSON parser.
> - But not every valid JSON document is a valid YAML document.

Not quite. JSON does not say that a JSON library MUST accept mappings
with duplicate keys; only that it SHOULD unless there's a good reason
not to. So a YAML library is technically a valid JSON library. It has a
good reason to reject duplicate keys (said reason is being a YAML
library, of course :-).

Put another way, a JSON file with duplicate keys is not a "safe" JSON
file - according to the JSON spec a JSON system MAY reject it. Which a
YAML-based JSON library does.

Anyone placing duplicate keys in his JSON files is in for a world of
hurt anyway. As you point out the JSON spec says you SHOULD NOT do that.
So don't :-)

> If my understanding is correct, I would like to have the spec 
> to describe this point clearer or to permit duplicated keys 
> in a mapping node.

Hmmm... perhaps so... I'd rather keep changes to the spec at this point
to be fixing errors, though, and this technically isn't one. I'll see if
its possible to sneak it in a sentence or two, though.

Have fun,

    Oren Ben-Kiki


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
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.