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.
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.




Leave a comment