JSON vs XML

For awhile now, XML has been the “way”. Everything speaks XML. Tons of tools are available for doing pretty much anything you want with XML. It is such a cool acronym that it is even being used in other acronyms like AJAX (Asynchronous Javascript And XML).

Let’s talk about XML for a minute. It allows you to specify pretty much any data structure you can imagine and validate that data using off-the-shelf tools. If you can create a DTD (Document Type Definition)Â or an XSD (XML Schema) then you can use XML to dramatically improve data interchange processes in any system or application. There is no doubt about it. XML is great at what it does. But…it has a problem.

For certain types of applications, XML has undesirable overhead. Overhead in terms of data bloat, parsing and validation. Depending on the nature of your data, XML can double or triple the size of your data. Yes, this is STILL a problem even in the exciting new broadband world we live in. You still want to get your data from point A to point B as fast as possible and XML can slow things down quite a bit. Also, the overhead of parsing XML is substantial. Again, in a world where the smallest desktop computer can easily outperform the supercomputers of 20-30 years ago, this may not seem like a huge problem. But it is…

Applications are being built differently today. More and more apps are being pushed onto the Web. Although the definitions differ, Web 2.0 seems to mean lots of cool features and services from one or more web sites delivering server side data in XML all held together by large amounts of Javascript (AJAX).

When I started really looking into AJAX, I was concerned about the overhead added by the X part of the acronym. But I kept seeing references to something called JSON. Finally, I stopped and started looking into this JSON thing. It didn’t take me very long before I realized that someone had taken the data structure specification syntax of javascript and used that as the data transfer mechanism. So, you encode the data using javascript itself and when you transfer it, you can objectify it using javascript’s eval(). And, the bloat is gone! The start and end tags become { and }. Not bad. Even if you use one character tags JSON still wins in terms of reducing the bloat.

After the full impact of this sunk in, I realized that the acronym was wrong. AJAX should actually be AJAJ. Or AJAJSON…ok, lets just leave it AJAX. The following article is a fantastic read for understanding the point that i’m trying to make.

http://www.developer.com/lang/jscript/article.php/3596836

XML definitely rules most areas of data exchange but the point is that JSON is definitely the way to go for AJAX applications.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s