XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Michael Kay: simple designs make easy things easier, difficult things more difficult

* Costello, Roger L. wrote:
>Would you give a concrete example of where JSON makes a difficult 
>programming task more difficult please? And bonus points if you show how 
>a more complex data design (e.g., XML) would not make the programming 
>task more difficult.

YAML is a superset of JSON. In many ways YAML is a better format than
JSON. I use a json2yaml conversion tool when I want to make JSON more
readable. One point there is that YAML has good support for multiline
strings, you can use nicely wrapped text instead of long "..." lines.

YAML supports anonymous references and cycle. If you do

  var a = {};
  var b = { "x": a, "y": a };
  var c = JSON.parse(JSON.stringify(b));

then b.x == b.y but b.x != b.y, the object identity is lost, and when
you do

  var a = {};
  a.a = a;

then JSON.stringify(a) will raise an exception because of the cycle.
Note that this is quite common, DOM nodes for instance are cyclic. As
YAML supports references, it does not suffer these problems (of course,
you would want a default-off parser option that lets cyclic objects
through as otherwise malicious input can make your code run in an in-
finite loop when you try to traverse the input; that is not a common
option however).

YAML supports multiple "documents" in one "file" which makes it easy to
combine many documents into one and it does not suffer from "forbidden
trailing comma" problems which require you to maintain state when
generating multiple items (if the program already generated an item,
append a comma before the next, or if this is the last item, to not
append a comma -style logic). That makes it hard to use it for logfile-
style data generation scenarios.

YAML has better Unicode support, you can encode U+E007F as "\U000E007F"
and do not have to apply complex calculations to derive a pair of "\u"
escapes as you would have to in JSON (you typically want to escape a
number of characters like white space characters as otherwise special
characters like zero width spaces are hard to make out and those might
be non-BMP characters).

YAML has proper support for comments, which makes it more suitable for
scenarios that require some documentation, like configuration files.

JSON also lacks support for values that arise often enough and that you
might want to preserve like NaN and Infinity.

Unfortunately YAML also has many other features and multiple versions
and implementations typically only implement subsets of it, and those
subsets can easily be incompatible with one another, a typical problem
is that some YAML serialisers insist on adding type annotations while
some YAML parsers are unable to read documents with type annotations.
And the specification is not exactly easy to digest either.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS