What ? No more XML in AJAX ?
Yeah, it seems like the emerging JSON format makes much more sense than having XML as the data-interchange format. In today’s data saturated world, web-programmers would be blissfully happy if the data doesn’t need some complex parsing. And JSON does just that. Consider a fragment of structured data that many “Ajax-ed” application of today could be receiving over the web:
firstname = Velma, lastname = Kelly
While the xml version could be (that needs parsing):
<name> <firstname>Velma</firstname> <lastname>Kelly</lastname> </name>
JSON is:
{'firstname':'Velma', 'lastname':'Kelly'}
which doesn’t need parsing at all. The json data as a string can be converted to a javascript object and used like this:
var jsonObj = eval ( '(' + jsonObjAsString + ')' );
var fname = jsonObj.firstname; // or jsonObj['firstname']
Useful, right ? And consider how much less space and effort it takes to handle JSON. Clearly the preferred data interchange format for the dynamic web applications, many of which can’t even use XHR (XmlHttpRequest) because of crossdomain security issue of browsers. The solution is using dynamic script elements and using JSON just makes the whole effort a lot easier.
Here is Douglas Crockford’s interesting blog post.
February 18th, 2006 at 12:56 pm
There are many reasons why XML is better than JSON. XML is complete structured notation when JSON in a simple context free grammar. XML was developped in order to allow a transferable translation for databases with query languages (like XPATH and XQUERY), whereas JSON does not have a query language. It is not possible to represent recursive structures in JSON.
The guys from google wrote an XML parser in Javascript which is used for Google Maps. In Google maps all the data that is transferred is represented in XML format which is parsed at the client and constructed the map.
March 7th, 2006 at 6:46 pm
You better check out xForms. Json is pretty lame