XML vs JSON !!! Dont compare.
Posted by sureshkrishna on October 13, 2007
Java Script Object Notation (JSON) has become quite famous since 2006 and it has gone into the major companies application frameworks. JackBe, Google and Yahooare some of the companies that have adopted the JSON in their products. JSON is the response format for many kinds (rss, rest, wsdl, atom, dao, etc…) of the web service responses. Industry has already been talking “If JSON is an alternative to XML”.
I would like to keep the JSON as just a data interchange format. I would not mix up XML and JSON for the data representation and data exchange formats. Following are some differences that i have seen from my own experience…
- XML parsing is very generic, you don’t have to care about the Types. JSON parsing on the other hand is very tricky.
- XML has the data representation and semantics attached to it. JSON is very good for data representation.
- Perhaps JSON data over the HTTP is faster than the XML.
- As a developer the code to parse XML is much cleaner than the code to parse JSON.
- Evaluating the JSON on JS is much faster and efficient. Due to its inherent support on JS, the learning cycle and manipulation of JSON data is faster than manipulation of XML by JS.
- For WEB2.0/RIA applications, where there is frequent data transfers between the browser and server, it makes sense to get the response in JSON and manipulate it in the browser.
- I have used XML as domain models representation. It can contain the cross references, can contain types and attach semantics with the help of Schema.
- JSON does not have any namespaces. I am not sure if this is an added advantage for JSON.
- JSON Does not have validator. Developer is supposed to validate what ever he gets.
- I love the random access XML via XPath. Can i do the same thing in JSON.
- XLink, XQuery are some of the cool things i like on the XML.
- I can represent the entire design of a system as XMI. It has references, schema support, i can validate, etc…
In my view JSON is a great format for the internet/web applications over the browser. Its not the question of XML vs. JSON; Its the question of When XML and When JSON.