nfirvine.comwiki

JSON

Filed in: Whinging.JSON · Modified on : Tue, 17 Aug 10

JSON

JSON is so hot right now. It's a superior alternative to XML for many reasons:

  1. It's shorter, since there's no need for end tags, etc.
  2. There's no futzing about with namespaces.
  3. It's not based on SGML, the ugliest, hardest to type language in the universe.
  4. It's almost immediately parseable in Javascript, and closely resembles constructs found in other languages (i.e., nearly a one-to-one mapping).

And so forth. It's practically the second coming.

But it's not without its shortcomings...

  1. JSON doesn't support comments, so is pretty much a write-off for any sort of configuration file. Just bloody skip them! (Some parsers do this anyway.)
  2. JSON forces the arbitrary decision to use double quotes '"' to the exclusion of single quotes "'" to denote a string. JavaScript proper doesn't have this limitation. Personally, I use single quotes wherever possible for the simple reason that they're easier to type. Especially when...
  3. JSON forces you to mark object keys explicitly as strings, wrapping them in double quotes. In JavaScript, a key that's a valid identifier needn't be quoted. It's just extra typing.
  4. JSON doesn't let you write an extra comma to separate array/object items. In Python, this is perfectly acceptable, and for at least one excellent reason: it's simpler for machines to generate. Otherwise, you end up with an inevitable "if this is not the last element, write a trailing comma" in all your for loops. Gross.

(To be continued...)


Powered by PmWiki