XML vs JSON !!! Dont compare.

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.

This entry was posted in java, software, technology and tagged , , . Bookmark the permalink.

0 Responses to XML vs JSON !!! Dont compare.

  1. Krishna, I agree with most of your points except #4 and #10.
    The usual case for XML -> Java conversion will try to map the xml to a bean graph, there are plenty of projects that provided that behavior (like xstream) int just a couple of lines. The same can be said about JSON, projects like FlexJSON and Json-lib (don’t mind the plug but that’s one of the reasons the library exists) will map a JSON string to a bean graph in a couple of lines (or even a single one) with little effort and most of the times in a non-intrusive way (that’s #4).
    On #10, XPath is not part of XML perse, it is an addon that happens to have plenty of tool support. JSON lacks something like XPath (for the time being) as a impl-language agnostic feature (what I mean is that XPath is not exclusive of Java or .Net) but in the meantime if you’re willing to branch out to other languages like (J)Ruby or Groovy you can use xpath-like expression support built into the language itself (not just for JSON/YAML).

    “Its the question of When XML and When JSON”, spot on! use it when its most convenient to your needs, not everything is a nail when you hold a hammer =)

  2. cfasky says:

    JSON has JSONPath: http://code.google.com/p/jsonpath/

    JSON is better when we use it as a way of exchanging data without the need of semantics

    pcdinh

  3. Yo, sure…. i am very positive about having a schema kind of stuff to JSON.
    It helps for many technology areas like UML Representation, Content Modeling, MetaFormats to adapt JSON and probably benefit from the compactness.

  4. Pingback: Blogs and RSS » XML vs JSON !!! Dont compare. Sciology = Science + Technology

  5. Lucas says:

    JSON is better to represent Data structures. Parsing JSON as an object is easier because you don’t need any validations, JSON has got types, so you don’t need patterns for data representation (Example Date patterns).

    XML is better for human editing. Configuration files are good examples of when XML is better than JSON.

    Java programmers will probably fall in love with JSON after seeing Google’s JSON Parser: GSON
    http://code.google.com/p/google-gson/

    It’s as easy as an Eval in Javascript.

Leave a Reply

Your email address will not be published. Required fields are marked *