There is a reason why JSON is becoming very popular as a data exchange format (more important than it being less verbose than XML): programmers are sick of writing parsers! But “wait”, you say – “surely there are XML parsers available for you to use so that you don’t have to roll your own…”. Yes, there are. But while XML parsers handle the low-level syntactic parsing of XML tags, attributes, etc…, you still need to walk the DOM tree or, worse, build one yourself with nothing but a SAX parser (Objective-C iPhone SDK I’m looking at you!). And that code you write will of course depend on whether the XML you need to make sense of looks like this:
<person first-name="John" last-name="Smith"/>
or this:
<person> <first-name>John</first-name> <last-name>Smith</last-name> </person>
or this:
<object type="Person"> <property name="first-name">John</property> <property name="last-name">Smith</property> </object>
or any of the myriad of other ways one can conceive of expressing the same concept (and there are many). The standard XML parser does not help you in this regard. You still need to do some work with the parse tree.
Working with JSON is a different, and superior, experience. Firstly, the simpler syntax helps you avoid the need to decide between many different ways of representing your data (as we saw above with XML) – much less rope to hang yourself with. Usually there is only one straightforward way to represent something:
{ "first-name" : "John",
"last-name" : "Smith" }
Even more important, if you are working in Javascript (which is very often the case when working with JSON), all you need to do is call eval on a JSON string to obtain a first-class Javascript object. This is huge. The subtle point here is that the output of an XML parser is a parse tree, not an object native to the programming language being used. With XML you are still dealing with syntax to a large degree. When you work with JSON you can go straight from a string representation to object (and back).
What makes this possible is that Javascript has syntactic constructs for describing composite data types literally. While virtually all languages have syntax for the literal description of objects of primitive types (integers (e.g. 5), strings (e.g. “hello world”)), not all languages have syntax for the literal description of objects of composite types. For instance, if you want to create a map in Java you need to do it procedurally:
Map m = new HashMap();
m.put("a", 1);
m.put("b", 2);
m.put("c", 3);
.
.
.
Java does not have literal syntax for maps. But languages such as Python and Javascript (and others) do. In Javascript we can define our map literally:
{ "a" : 1, "b" : 2, "c" : 3, ... }
As it turns out, such sub-languages are a great match for data interchange formats that are both human and machine readable.
As for XML… it’s just not the best for structured data interchange (even with some of the cool Object/XML mapping technologies out there). It works well for markup (i.e. HTML) of text but not as a language for structured data. For that developers want something they don’t have to parse all the time.


Pingback: Our Investment in MongoLab | Foundry Group
Pingback: Investment » Blog Archive » Our Investment in MongoLab | Foundry Group
Pingback: Good explanation on why developers prefer JSON | tivoliandme
Pingback: Why is JSON so popular? Developers want out of the syntax business. | MongoLab « The Ramblings of Ben
Pingback: JSON is just easier to use than XML | Sean Walther’s Blog
Pingback: JASON vs XML - Kenneth Tucker
Pingback: Web | Fragments
Pingback: Link: Why is JSON so popular? « Tangled Helix
Pingback: Всем сотрудникам отдела! «
Pingback: JavaScript Magazine Blog for JSMag » Blog Archive » News roundup: Paper.js, Fathom.js, test262
Pingback: Weekly Links– 2010_24 (50 for Web Devs & Other Geeks) :Misfit Geek
Pingback: Recently in Web Development (July Edition) | FlexLib
Pingback: Recently in Web Development (July Edition) - Furlogy.com
Pingback: Recently in Web Development (July Edition) | Technology Story
Pingback: Web Development articles, tutorials, help » Blog Archive » Recently in Web Development (July Edition)
Pingback: Recently in Web Development (July Edition) | Shadowtek | Hosting and Design Solutions
Pingback: Recently in Web Development (July Edition) | Website Design Tutorials & Guides
Pingback: Web Development Company, Ecommerce News » Recently in Web Development (July Edition)
Pingback: Recently in Web Development (July Edition) » abdie.web.id
Pingback: Design Magazine » Recently in Web Development (July Edition)
Pingback: Recently in Web Development (July Edition)
Pingback: Recently in Web Development (July Edition) | Web Design Northamptonshire
Pingback: Recently in Web Development (July Edition) « Leonardowesleidiniz's Blog
Pingback: Recently in Web Development (July Edition) | Jetcat
Pingback: Recently in Web Development (July Edition) | Allprowebdesigns.com
Pingback: My Stream » Recently in Web Development (July Edition)
Pingback: Recently in Web Development (July Edition) | Neil Kearney Design
Pingback: Parser for XMLTV format and SchedulesDirect data « BCmoney MobileTV
Pingback: Facts about Adipex-p | Health Insurance Benefits Today
Pingback: harbaremnmn
Pingback: website
Pingback: Have Fun On Your Vacation
Pingback: WordPress Freelance
Pingback: wifi phones: PowerGen Dual Port USB 2.1A 10W AC Travel Wall Charger – White