December 2008 Archives

XML v JSON

| | Comments (0) | TrackBacks (0)
In putting together some Web services stuff for a client I've been struck by the weird comparisons I've seen between JSON and XML.

Typically, XML is fingered as a "heavyweight format" as opposed to the lightweight simplicity of JSON.  This is very hard to understand.

Here is a simple XML format for transfer of information:

<N v="V"/> (10 characters to send 2 bytes)

Here is the equivalent JSON:

["N", "V"] (10 characters to send 2 bytes)

It's all a question of how strongly you are willing to make your assumptions about data formats.  Given the comparison is JSON, which is an "all assumption, all the time" format, it seems odd that JSON was not implemented as an XML format, and that the "examples" of XML formats for data transfer that one sees in JSON comparisons look more like this:

<EgregiouslyLongWrapperName SomeIrrelevantVariable="VeryLongValue>
  <NameTagNameMadeAsLongAsPossible AnotherIrrelevantVariable="MoreWaste">
      <NameValue Wrap="YesSendAsCDATA">
           N
      </NameValue>
  <NameTagName>
  <ValueTagNameMadeAsLongAsPossible AnotherIrrelevantVariable="MoreWaste">
      <ValueValue Wrap="YesSendAsCDATA">
           V
      </ValueValue>
  <ValueTagName>
</EgregiouslyLongWrapperName>

Of course, unlike JSON, XML scales up nicely to add more information, which may indeed include type information.  But XML is a compact, efficient tool in the hands of anyone who knows how to use it well, and one should always be highly suspicious of hand-rolled "efficient" formats like JSON.  One suspects they are generally created by people who can't be bothered to spend a few days learning the standard-compliant way of doing the job properly, and so have invented yet another wheel that is only approximately round.

About this Archive

This page is an archive of entries from December 2008 listed from newest to oldest.

November 2008 is the previous archive.

March 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Categories

Pages

Powered by Movable Type 4.1