And The Winner of the JSON vs. XML Battle Is...

by M. David Peterson

... Uhh, since when were they in competition with one another?

mikechampion's weblog

As a 10 year XML veteran, and informal minister of propaganda for the "XML Team", aren't I supposed to leap to XML's defense? I just can't summon the energy.


And I can't blame you, Mike! Why waste the energy of defending XML when theres nothing to defend!?

Quick show of hands from those who subscribe to a JSON Web Feed?

Okay, how about an XML Web Feed?

Okay, now lets try how many of you find that if you don't want and/or need any of the extra stuff that working with the XML source provides, JSON is a really nice way to serialize XML data (e.g. a Web Feed), or any other source of data/data format for that matter, such that you can be more productive with less code inside of your web apps?

So tell me again... Where's the comparison? Where's the battle?

If anywhere, it must be in your mind (speaking to those who believe it's one over the other, but "not both!"), cuz' it does not exist! GET OVER IT!

10 Comments

Jim Plush
2006-12-21 08:11:34
The only people who believe there is a war between json and xml are novice programmers. Programming is about building a healthy tool chest of available assets. Does the job call for JSON? Great you know it, Does the job call for XML? Great you know it. I readily use both in my applications, depending on the requirements.
Michael Champion
2006-12-21 08:28:46
The same quite rational response could be given about the "war" between WS-* and REST, but that has caused quintillions of electrons to change state in vain for the last 5 years or so. The fact remains that some people with a strong attachment to a given technology howl when it is declared to be less than universal. I completely agree that the metaphor of "keep a healthy tool chest and use the right one for the job at hand" is the appropriate response to all these "wars", but such boring pragmatism doesn't get Diggs or Pagerank.
M. David Peterson
2006-12-21 09:03:21
@Jim,


Well said!

M. David Peterson
2006-12-21 09:10:09
@Mike,


>> The same quite rational response could be given about the "war" between WS-* and REST, but that has caused quintillions of electrons to change state in vain for the last 5 years or so.


And will no doubt continue for five more... Don't people have better things to do with their time? (don't bother answering that question... I already know ;)


>> but such boring pragmatism doesn't get Diggs or Pagerank.


Isn't that just the most lame thing on the planet -- It's absolutely spot on true, but absolutely lame that being pragmatic means that nobody gives a damn.


Well Mike, for what its worth, I Digg your pragmatism >> http://www.digg.com/software/Being_Pragmatic_Won_t_Get_You_Digg_d :D

Json
2006-12-21 12:47:53
XML does have ten years behind it, so of course there will be more tools and supoport for it. But that not mean JSON is not better!
1) JSON is thinner than Xml (slightly, no big deal really)
2) JSON is native to the client. Having to load a specialized library to transform my data SUX.
3) JSON can do cross domain calls that XmlHttp requests can not
4) It is easier to encode / escape in JSON than XML
5) JSON can define a function and data in one pass
6) JSON can be used as a PSUH from the server (ok - it really is a managed pull, but at least it is not POLLING)
M. David Peterson
2006-12-21 14:53:43
@Whoever you are,


>> XML does have ten years behind it, so of course there will be more tools and supoport for it. But that not mean JSON is not better! <<


Did you even read the post?


If you want to use JSON, then use it. But JSON isn't a drop in replacement for XML. It provides a simple way to process data when there is no need for anything other than the somewhat structured name/value pairs that JSON provides.


When it's enough to get the job done, use JSON. When it's not, don't.

M. David Peterson
2006-12-21 16:40:57
@Whoever you are (again),


Just because I'm in a pissy mood at the moment, I am going to take your reasoning and run it through the ringer,


> 1) JSON is thinner than Xml (slightly, no big deal really)


Yep. That's one nice thing about JSON. It's lightweight. Actually, it is a big deal. JSON is a lightweight syntax, so when dealing with REALLY SLOW parsing technologies, like, for example... JAVASCRIPT, the lighter, the BETTER!


2) JSON is native to the client. Having to load a specialized library to transform my data SUX.


WHAT??? Are you on CRACK???!!! Since when did you have to load a "specialized" library to load XML? RTFM, Whoever you are!


3) JSON can do cross domain calls that XmlHttp requests can not


Yep. That was a poor design call on the part of the browser developers. Then again, I doubt any of them really believed that a seven year old technology would suddenly become the "latest and greatest" when there were a pluthera of other technologies that were being developed that, at the time, seemed like natural replacements for the aging technologies first introduced when the Internet was like five minutes old and nobody had a clue what they were doing.


4) It is easier to encode / escape in JSON than XML


Did you really just say that? Have you ever written a line of code in ANYTHING other than Javascript (CSS and HTML *DO NOT COUNT*!)


5) JSON can define a function and data in one pass


HUH??? One pass of what??? The interpreter??? The SLOW AS MO-LASS-ES JAVASCRIPT interpreter???!!! Who gives a damn what it can do in one pass when it takes 100 times as long to make that pass in the first place???!!!


6) JSON can be used as a PSUH from the server (ok - it really is a managed pull, but at least it is not POLLING)


Dude, seriously... What are you talking about? We're talking about HTTP, here, which is a stateless protocol. Now, there are a few technologies (like Comet, for example) out there that make an attempt to be more push-like, but JSON isn't the reason... Push, Pull, or Poll has nothing to do with the format of the data, and EVERYTHING to do with the underlying capabilities of the protocol being used.


Dude, seriously... I don't mean to come across mean, or rude, or whatever else... But you really should consider reading up a bit more on things.


Just my opinion, however... No doubt, you have yours.

Kurt Cagle
2006-12-21 20:50:43
To Mike -


Evangelists can get tired carrying the damn flag after a while - I know I did for a bit with SVG, though I still find it handy now and then to do quick and dirty (okay, slow and dirty) animated graphics. XML is a huge technological field now, no longer even remotely at the point where you had to explain to confused managers why it wasn't EML. I find as well that occasionally I, dedicated declarative programmer that I am, still occasionally crack open my copy of Stroussup's or Knuth's masterworks and just indulge in an orgy of algorithms, before returning to the battlefield and picking up the flag (though don't tell my wife).


To our JSON enthusiast here -


Yeah, JSON is cool, and you can do all kinds of very neat things with object templates in Javascript that actually make the language fairly useful in the browser context. What JSON lacks, however, is structure. The wise client architect knows that you build the bones of an application with XML, the muscles with JavaScript, in or out of bindings, and the skin of that application with CSS or SVG.


Also a crucial point - web browser developers are not dumb. They recognize that you CAN pass logic into or out of the browser via JSON bypassing the restrictions on the XMLHttp stack - and one day very soon a hacker will figure out how to do exactly the same thing and cause all kinds of mayhem, and the loophole will be closed. The domain restrictions exist for a reason. Do you REALLY want to trust in a technology that has the power it does only because of a loophole that will likely disappear before the next browser version appears?


M. David Peterson
2006-12-26 11:08:54
@Kurt,


>> and one day very soon a hacker will figure out how to do exactly the same thing and cause all kinds of mayhem,


It's actually already happened. In fact, there are several cross-site scripting worms/viruses that have made there way out into the wilds of the internet, though don't tell the folks at Apple -- They'll either claim that it's not their fault, or that its Microsoft who is to blame, but either way, Mac's "are safe/immune", damn it! ;)

hasting
2007-06-17 17:57:54
Hey M. David, great article. I completely agree with your opinion
hasting