Is JSON surpassing XML or it is just a mirage with the advent of new supporters of JSON?
Is JSON surpassing XML or it is just a mirage with the advent of new supporters of JSON?
The 3 Main Reason for the thought.
1. With the advent of many NoSQL DBs like MongoDB, CouchDB etc., JavaScript framework like AngularJS, Backbone.js etc., and server side runtime Chrome V2 Engine & platform Node.js, usage of JSON format for data files has got increased when compared to XML.
2. Even in Java, we have been moving away from XML configuration by replacing them with Annotations. Which also makes things look like we have become less bent towards XML.
3. Micro services can expose data in either XML or JSON format. People prefer Micro services in order to reap the elasticity to form Agile teams and leverage cloud computing. More & More I find myself working on many micro services in now & in future.
Here is a reference with data stating JSON surpassing XML from 2013 in its Usage.
Why & When the Question rose?
Currently I am working on a Java application which acts as a REST based Web Service. If I was given a chance to decide on JSON or XML, I would have went for the support of both in the same application with Content Negotiation Strategy. And one can move more steps further to support xlsx & rdf format support with Content Negotiation Strategy. I know it is a whole lot of "end points" and a "huge commitment" to support them in future. At least the design can be made flexible to support different format in the future despite only one format is actually supported, but nothing happened as such in my case.
What is the Problem?
One reason for our inclination towards JSON is that the consumer of the service is a Mobile Application either iOS or Android which makes use of JavaScript and it is good with JSON format data. If I could consider the Web Service as my Product Which I would sell, I hope I will not certainly reduce my scope of sale without a support to Consumers who can consume only XML or other formats. Given the situation that the application only supports JSON and its domain models are getting flexible only sufficient enough for JSON, the question, Will it have any impact if the web service product requires support for XML & other formats? raises. Let us even ignore other format and restrict ourself to XML alone as it is ubiquitously supported in many application and it is a full fledged language and there are many other language schemas available based on XML.
The above situation pushed me to look into the Pros & Cons of both JSON & XML formats.
While I explored their differences, here is what I could find.
What data structure JSON & XML requires during data consumption?
XML - Tree (Require Transformation to parse in programming World)
JSON - Array (Easy to parse in programming World)
XML requires translating the structure of the data into a document structure. This mapping can be complicated.
JSON structures are based on arrays and records. That is what data is made of.
XML structures are based on elements (which can be nested), attributes (which cannot), raw content text, entities, DTDs, and other meta structures.
Which format is Extensible?
XML.
Many Custom Tags are available and can be formed easily.
It is a language by itself, where as JSON is just a Notation.
Supports Many Data Types likes Images, Charts etc., than JSON.
Supports Namespace to resolve conflicts.
(Extendibility breeds flexibility. Flexibility always is accompanied by Complexity)
Which format is Human Readable at all circumstances?
JSON.
XML may lose readability once its Extendibility gets harnessed. Most of the WSDL and SOAP request are not readable without a tool like SOAP UI.
Which format support custom data types & formats inherently?
XML.
JSON has limited support for data type. Images, documents cannot be easily included in JSON format.
Which format is Really Concise and requires lesser bandwidth?
JSON.
They do not have closing tags as XML has and no Angular Brackets. Here is a Informal Benchmark.
Which format specifically designed to serialize data?
JSON.
XML requires XML Schema to serialize data Unambiguously. one simple Informal reference.
Which format requires JavaScript support on Browser?
JSON.
Which format will require More processing time on the Browser?
JSON.
Browser inherently should support XML format. After processing, XML (ie., HTML) output is required to be formed. Here is some reference.
Which format will require more processing time in Server (Java & JavaScript)?
XML.
As it requires tree structuring and JSON requires array structuring. one has to go with the Pros and Cons of data structures based on the processing required over the format.
Which format allows one to create more no. of views?
XML.
With the support of XPATH, XSLT, XQUERY, XPOINTER & XLINK, it is easy to form various views of XML
Which format is Internalized?
BOTH.
Both use Unicode. (I was not really aware that JSON uses UNICODE under the hood, because I have never set "UTF-8").
Can I mix JSON & XML?
NO.
There is no synergistic effort found so far, rather they obviously impede each other in most of the cases.
Which conversion is easier, JSON to XML or XML to JSON?
JSON to XML.
JSON to XML is easier as JSON is simple and does not support complex data types.
Which format can be easily validated?
XML.
With DTD or XML Schema, the complex types definition reuses the elementary type definitions there by making it easy for maintenance of validation code.
Which format can be easily mapped to Object Oriented systems?
JSON.
XML is document-oriented. JSON is data-oriented. JSON can be mapped more easily to object-oriented systems.
Which format Support Data Type other than String?
JSON.
XML is completely string based. JSON format allows to provide boolean, numbers & array.
The Consonance
The application on which I currently work certainly does not requires to leverage XML benefits and since it is easier to convert JSON to XML, I felt some peace with the above observations, I can still support XML when needed and I can make my fastidious step when the domain model and use cases becomes complex to support both JSON & XML features to make the application support both or switch to appropriate one.
Despite the fact that annotations replacing XML and JSON replacing XML. We could still see that XML find its place for complex type abstractions, type maintenance with namespace, View Transformation and Extractions.
My Conculsion
JSON might have occupied most space of XML by holding many of the features in common with respect to XML and sometime JSON surpasses XML with its own constraints & limitations, but still XML does finds its own space to stand distinct.
More References to read:
http://www.json.org/xml.html
http://stackoverflow.com/questions/4862310/json-and-xml-comparison
http://stackoverflow.com/questions/20859453/difference-between-json-xml-and-rdf

Comments
Post a Comment