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 (http://code.google.com/apis/ajaxsearch/) and toolkits (http://code.google.com/webtoolkit/). Other companies like Yahoo too entered quickly into the foray (http://developer.yahoo.com/maps/ajax/). In December 2005 Yahoo published JSON based web services (http://developer.yahoo.com/common/json.html) while Ebay provided XML2JSON transformer (https://json-xslt.codebase.ebay.com/).
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 (http://developer.berlios.de/projects/jsontools/), json-lib (http://json-lib.sourceforge.net), etc are some of the open source tools for Java-JSON conversion. JSON website (json.org ) 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: http://www.json.org/
Using JSON with Yahoo Webservices: http://developer.yahoo.com/common/json.html
XSLTJSON: http://www.bramstein.nl/xsltjson/
XML2JSON: http://code.google.com/p/xml2json-xslt/
XML2JSON: https://json-xslt.codebase.ebay.com/
JSON tools http://developer.berlios.de/projects/jsontools/
Json-lib http://json-lib.sourceforge.net
Labels: AJAX JSON XML
0 Comments:
Post a Comment
<< Home