[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Michael Kay: simple designs make easy things easier, diffi

  • From: Bjoern Hoehrmann <derhoermi@gmx.net>
  • To: "Costello, Roger L." <costello@mitre.org>
  • Date: Tue, 12 Nov 2013 17:02:36 +0100

Re:  Michael Kay: simple designs make easy things easier
* 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��H��ann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dageb��· PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 


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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.