Welcome!

XML Authors: Max Katz, Yakov Fain, Keith Mayer, Trevor Parsons, Jayaram Krishnaswamy

Related Topics: XML, AJAX & REA, Web 2.0

XML: Article

JSON vs XML - A Jason vs Freddie Sequel

It's not the latest sequel to the "Jason versus Freddie" movie, it's one of the decisions you need to make

(April 5, 2006) - It’s not the latest sequel to the “Jason versus Freddie” movie, it’s one of the decisions you need to make if you’re rolling out a Web 2.0 product. Make the wrong choice, and your project and reputation can suffer. Make the right choice, and you can be a hero. There aren’t any easy answers, but I can take you on a tour of the technology and the decisions involved so you can make a better-informed choice. During our tour I promise you won’t be attacked by a man in a hockey mask, so sit back and enjoy the ride.

On one side, we have the XML/XMLHttpRequest camp.  It uses the world-wide XML standard for data. It also involves using the XMLHttpRequest capabilities of most all browsers to retrieve information from a server. We use the XMLHttpRequest object to get XML from our server. So when we say XML in this article we really are talking about both the data format and the data transportation pattern: the two are tightly linked in this area. Due to security concerns, the server has to be in the same domain as the web page. We gotta own it. So if you’re viewing a page from www.bugscratch.com, you can get data from the server at bugscratch.com, but not at weasels.bugscratch.com or at weasels.com. To get around this limitation, you have to use a proxy server: clients hit your bugscratch.com server and then the server goes to the rest of the web and finds information to return to the client. Processing happens asynchronously – your users can continue browsing the page while your code goes off and fetches information. Nearly everybody is a big player in this arena, including Microsoft, IBM. If you can name a big software company, they’ve got an AJAX XML toolkit.

On the other side, we have the JSON camp. JSON stands for JavaScript Object Notation. JSON is a way of formatting information so that it is native JavaScript. It’s not associated with any kind of data transportation pattern. When your data comes back from the server, it’s already in a JavaScript object format. Many developers consider JSON easier to read than XML, although personally I find them both equally readable once you get used to them.

So how can you compare a data format with a data transportation system? Aren’t they two different things? Can’t you just send JSON inside your XML? And isn’t this all called AJAX anyway? AJAX stands for Asynchronous JavaScript and XML. Where’s JSON in that?

As they used to say in a show when I was a kid, “grasshopper, you have much to learn.”

First, you can just embed JSON in your XML and badda-bing, badda-boom, you got both technologies. But you can also send JSON directly from the server to your browser, without any XMLHttpRequest object. You ask the server for information, and it sends you pre-formed Javascript Objects ready for you to use. JavaScript is not just data – you can also put methods and all sorts of goodies in JSON format. Would you rather have XML or pre-formed JavaScript objects? It probably depends on what you want to do with them. At the lowest level, if you are taking the XML and applying XSLT to make XHTML, then XML is better. On the other hand, if you are making procedural decisions in your JavaScript based on objects and their values (or methods), then JSON has the edge.

The plot, however, thickens. Because JSON is transportation-independent, you can just bypass the XMLHttpRequest object for getting your data. Bypassing the XMLHttpRequest system is an interesting option that you may have not considered, and in my opinion it is the primary benefit of using JSON. The acronym AJAX doesn’t really work that well for this pattern, however. I suggest we call such systems XJAX systems, as I explain below.

Meanwhile back in the XML camp, one of the great benefits is that it seems like everybody is working over here. If you want to buy a package that does it all, you can find a lot to peruse. For most of us, we want something to take out of the box and start using, and the XML/XMLHttpRequest guys have it. And they have a lot of it. You can get big, full-featured, big functionality systems. Plus you’ve got a company to back you up in case of trouble. For the Microsoft fans, Atlas is rolling out. Infragistics is AJAX-enabling their suite. Even smaller companies like RicherComponents are stepping up to the AJAX plate in a big way. For you Linux folks, just name the big player and they’re there: IBM, Sun, Opera. And let’s face it: if you still want JSON, just stick it in the XML on the way back to the client. These are some powerful benefits for most consumers.

In addition, we’re not just talking toolkits operating at the lowest level. Some of these suites have fully formed tool groups that do all sorts of neat things for the client. It’s truly turn-key development: complete packages that snap right into your development environment.

XJAX, however, has a secret weapon in its toolkit which is as just as powerful. Since JSON is legal JavaScript, you can get it from anywhere. After all, you can’t very well have a world-wide web only running programs from one server, can you? Everything has to interoperate. When you put a Technorati link on your site, you’re running a bit of code from the Technorati site every time a user visits your site. Same goes for Google Analytics, or any of a zillion other examples.

So that means when you use JSON, you can get data from anywhere, not just your own domain. There’s no more proxy server nonsense. [Insert long argument about security here, which I will not cover for the sake of brevity] There is also a subtle change to the business model which might have a big impact. It means the old concept of server-based development is changing. Why’s that?

Most of these companies offering solutions are offering server-based solutions. That is, you install something on your server which then delivers JavaScript code to the client to make all the good stuff happen. (Yes, there are companies offering AJAX products on the web, but this is a development discussion, not a product discussion) The assumption is that companies sell toolkits to developers which then install it in their development/test/production system. Sales are made to folks who write stuff on the server. The products, for as much functionality as they provide on the client, are really just server products. All the instructions will be how to configure your server to use the tools, how to write programs on your server to make the client act in such-and-such a way, etc.

The world has changed. When I wrote my latest Web 2.0 application, it was a toolkit for bloggers. (shameless plug: visit batBack and check us out! It’s the coolest blogging toolbox on the web today!) If you were writing a blogging toolkit, the traditional way would be to write some server tools for a blogging engine, say MovableType and PHP, and then sell the toolkit to people who used the server tool MovableType.

But think about it – do I want to provide a product to folks who own a certain server, OS, and blogging system? Or am I providing a product for all bloggers to run on whatever blog they have? My customer is any blogger or reader – the world of blogging -- not people with a certain server system or browser. I am making solutions for a certain problem domain, not a certain technology domain. I want folks to add just one line of Javascript to their blogging template and have a complete blogging toolkit no matter which blogging engine or browser they are using. This is a major change and you should be aware that it is happening.

XJAX and JSON lets me do that. You can call it “serverless” programming. Users drop small pieces of JavaScript into their HTML to get big functionality. XJAX stands for X-domain JavaScript And XML (Yes, you can still send XML inside your JSON.) Sure, there is a server, but the server isn’t the key element in the food chain anymore. In fact, from the web developer’s standpoint, it’s just a minor player. You can take a server system that does one thing well – say deliver blog content to browsers, and add dozens of gadgets and whizbangs without having to be a server developer or being concerned about server tools or environment. Outsource the trivial commodities, grab the functionality for free, and concentrate on your goal and not the development details.The world has changed. If you’re a developer, Average Joe is taking your place, and the reign of the server is ending as we know it.

I don’t want to make this sound like a knock-out for JSON, because it’s not. I’m not aware of very many XJAX toolkits out there except for mine. Dave Johnson has some of these same ideas over at eBusiness Applications. Yahoo is also working in this area, and you should check out their JSON API.  It’s good to be in the lead, and this is one of those situations where the problems and technology come together in exactly the right way to catch on fire.

You should also consider that there is a lot of corporate development in which you own the browsers and you own the servers. You need to get up to speed and working right away. Having one vendor control all the processing on the browser is not a bad thing.  Who wants to go through brutal low-level Javascript coding if they don’t have to? (Trust me, you don’t.) For those shops (who are the majority) I would say find a good AJAX company and product and enjoy.

JSON has benefits too, as we’ve shown. If you’re doing something a little more free-form, if you’re looking to push the envelope of what’s possible, then I would go the JSON route. Whatever your choice, be aware that having preformed JavaScript delivered to your browser, as Martha Stewart would say, is a good thing. In the duke-out between JSON and XML there may be no knockouts, but there are a lot of points scored by both sides.

Some of the technologies mentioned here may be covered by intellectual property law. You should contact the author if you have further questions.

More Stories By Daniel B. Markham

Daniel Markham is a hands-on software architect who over the past several years has become a RUP mentor and Technology Strategist. Programming in all major languages and database platforms, his clients include Pitney Bowes, Ford, Charles Schwab, and the Department Of Defense. Daniel is the Principal Partner of Bedford Technology Group located in SW Virginia. He is the inventor of the only online multi-standard process evaluation system (www.MarkhamAssessmentTool.com) He is currently developing a free toolkit for bloggers using Web 2.0 technologies. batBack installs in seconds and requires no programming skills or special server configuration. It runs on all major blogging engines and browsers. It's also fully skinnable and extendable. You can find more about the batBack blog toolkit system at www.batBack.net You can reach Daniel at [email protected]

Comments (10) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
tom mcdonald 04/17/08 07:25:51 AM EDT

this doesn't make sense. I'm a ajax developer and so might be biased against xjax, but at the very least I should be able to understand what you are talking about.

You talk about serverless development, but w/o a server you have no place to house your proprietary content. The serverless example you give is blog content, but if I'm hosting a site and the blog feature goes down then I get the tix (not some xjax provider). Worse, what if xjax provider loses my data.

It seems your prognostication doesn't stand up to my simple reality tests and thus I must not be getting it because you seem like a smart person and I would assume you apply the laugh rule.

Web 2.0 News Desk 12/26/06 12:15:08 PM EST

It's not the latest sequel to the 'Jason versus Freddie' movie, it's one of the decisions you need to make if you're rolling out a Web 2.0 product. Make the wrong choice, and your project and reputation can suffer. Make the right choice, and you can be a hero. There aren't any easy answers, but I can take you on a tour of the technology and the decisions involved so you can make a better-informed choice. During our tour I promise you won?t be attacked by a man in a hockey mask, so sit back and enjoy the ride.

Dave Webster 05/26/06 06:58:29 AM EDT

Interesting to see a lot of JavaScript/ECMAScript being used for these Web 2.0 applications. I guess, with the current climate of stable browsers and adoption of AJAX, we can think seriously now about engineering serious client-side scripts.

Rafik kafel 04/12/06 02:43:39 PM EDT

Don't you think "Asynchronous Javascript And XML" is a misnomer for a methodology/framework that is based on extensions?

I propose "Asynchronous Javascript Application eXtensions" instead.

Any thoughts?

Thanks

Rafik kafel 04/12/06 02:43:30 PM EDT

Don't you think "Asynchronous Javascript And XML" is a misnomer for a methodology/framework that is based on extensions?

I propose "Asynchronous Javascript Application eXtensions" instead.

Any thoughts?

Thanks

Rafik kafel 04/12/06 02:41:46 PM EDT

Don't you think "Asynchronous Javascript And XML" is a misnomer for a methodology/framework that is based on extensions?

I propose "Asynchronous Javascript Application eXtensions" instead.

Any thoughts?

Thanks

Mike Goldwater 04/12/06 05:27:48 AM EDT

Hi,
You are sending out your hitherto very interesting newsletter in an illegible font. Although we baby boomers are are still very much active our eye-sight might no longer be 20/20. Please consider all your potetial audience and use a larger font.

Thank you,

R Martin Ladner 04/11/06 10:10:39 AM EDT

Where do I learn more? You have my attention. Now how do I use use JSON, where can I find examples, and how does XJAX (mentioned in your earlier article) avoid crippling cross-domain blocks? =Marty=

xjax 04/07/06 07:20:08 AM EDT

So that X stands then for the cross (x) in "cross-domnain" is that it?

SYS-CON Brazil News Desk 04/05/06 08:16:59 PM EDT

It's not the latest sequel to the 'Jason versus Freddie' movie, it's one of the decisions you need to make if you're rolling out a Web 2.0 product. Make the wrong choice, and your project and reputation can suffer. Make the right choice, and you can be a hero. There aren't any easy answers, but I can take you on a tour of the technology and the decisions involved so you can make a better-informed choice. During our tour I promise you won?t be attacked by a man in a hockey mask, so sit back and enjoy the ride.