There are times when you may be unsure what format to choose when transmiting data between a server and web application. Here are a few reasons why you might choose to use JSON rather than XML and a few why you might choose XML rather than JSON.
What is JSON?
What is XML?
Extensible Markup Language (XML) is a set of rules for encoding documents in machine-readable form. XML’s design goals emphasize simplicity, generality, and usability over the Internet.
Reasons to choose JSON over XML
1. JSON requires less tags than XML – XML items must be wrapped in open and close tags whereas JSON you just name the tag once
2. Because JSON is transportation-independent, you can just bypass the XMLHttpRequest object for getting your data.
5. You can get JSON data from anywhere, not just your own domain. There’s no more proxy server nonsense.
6. Yahoo has a really good YUI2 JSON API.
7. JSON is easier to read than XML – Obviously a personal preference
Reasons to choose XML over JSON
1. Easy to take XML and apply XSLT to make XHTML.
2. XML is supported by many more desktop applications than JSON.
4. Simply, AJAX includes XML in it and not JSON.