Khanderao on Emerging And Integration Technologies

Saturday, February 24, 2007

Replacing XML with JSON in Ajax: Is it ready?

JSON (JavaScript Object Notation) is a data interchange format (based on subset of JavaScript Programming Language, Standard ECMA-262 3rd Edition), which is becoming popular alternative to XML in Ajax (Asynchronous JavaScript and XML) based software. It is comparatively lightweight than XML.

It has simple message format: JSON message is constructed using very simple data types and data structures similar to those available in most of the programming languages. JSON has objects and arrays. Objects are collections of Named value pairs while arrays are ordered lists of values. A value can be a string, a number, a boolean (true or false), null or an object. This message format makes easier for Ajax to access the data.

Ajax – JSON made for each other? A natural fit? Since Ajax itself is JavaScript based, JSON becomes a natural fit. You do not have to parse or evaluate JSON object within your Ajax code, you can immediately access the elements inside it. JSON object can be directly passed to JavaScript eval function. For example, var obj = eval( '(' + returned_json_text + ')' ) . This is fast and easy. Moreover, supported by most of the browsers and Ajax based tools.

Momentum: Though, neither JSON nor Ajax is conceptually new, in last couple of years both in general but Ajax in particular got a momentum. Ajax has provided a way to implement web based rich client. Ajax become mainstream with Google’s backing which provided Ajax based search ( and toolkits ( Other companies like Yahoo too entered quickly into the foray ( In December 2005 Yahoo published JSON based web services ( while Ebay provided XML2JSON transformer (

Is it ready? While we witness a momentum, the real question is what do we need to make it end to end working? Do we have adequate tooling? What is the benefit? Is it worth? Is it robust? Secured?

While it does make sense for a browser based, in other words JavaScript based, clients to prefer JSON, the end-to-end applications need support from middleware and backend. In a typical scenario data goes back and forth through many layers between a database to a client. It gets mapped to the data structures on language implementing business logic; it may be converted to XML in a middleware. Before sending to the client it may need to be transformed to JSON. If the solution is dedicated to Ajax based client, then you do not need to convert from native to XML and then XML to JSON. You can directly serialize in JSON form. Jsontools (, json-lib (, etc are some of the open source tools for Java-JSON conversion. JSON website ( ) lists many such libraries for different languages. You can use them. This path narrows your software to JSON/Ajax based solutions compared to XML based Web services provides a wide variety of applicability.

Over last decade, a much more mature and robust infrastructure has been build around XML. In contrast with it, most of these JSON based tools/libraries are open-source and, as of today, may not be well supported. You may use them at your own risk. That’s one drawback JSON has. It lacks tooling support and standardization for different language mapping. In Java world, do we need a JSR? However, I hope that some of these open sources may become Apache projects and start evolving towards standards or become de facto standard. It all depends on how much industry support JSON gets in Ajax world.

Security, and robustness are next issues that need to be addressed. Since JSON code may carry security risk particularly due to JSON text may carry Java scripts dynamic script tag. Heavy-duty JSON applications reveal browser specific issues like memory leaks.

In summary, there is a good promise with Ajax –JSON (additionally REST); you may start some internal pilot projects. However, it would need some more time and resources to mature JSON in this combination.

Introducing JSON:

Using JSON with Yahoo Webservices:




JSON tools



Add to Technorati Favorites

Save This Page on


Post a Comment

<< Home