|Listing 1.1 : JSON payload example|
"title": "Backroad Mountain Bikes",
"name": "Stump Jumper",
Now compare this last JSON listing to its XML equivalent in Listing 1.2
|Listing 1.2 XML payload example |
<description title="Backroad Mountain Bikes">
<cost salestax="CA" rate="7">
Prior to the emergence of Ajax, communication between a browser and its corresponding server application took place synchronously, or in other words, every request made by a browser required a complete screen refresh to obtain new data from the server. This of course minimized the need to parse data on the browser, with access to server side applications for customizing HTML markup on each request and the inevitable time lag experienced by a client browser there was rarely, if ever, a need to manipulate data on the browser directly, much less a need for XML or JSON.
With Ajax's first "A" standing for asynchronous and the "X" for XML, this pattern has changed considerably. Ajax has given way to the extremely common practice of transferring data between a browser and server application without the user awaiting a screen refresh -- or what is know as asynchronous communication -- and making such data exchange in XML fragments.
So may now be asking yourself, should I always use JSON instead of XML payloads? The short answer is, if your service client will be a browser then yes and if you will be using Ajax then it would be a definite yes. The question is actually reminiscent of other client/server technology design choices. Should you use XML when you knowingly have a Java/RMI client/server round-trip scenario? Or VB/.NET/DCOM over XML? Or CORBA instead of XML?
In terms of maturity, JSON's early beginnings have given it a series of stable implementations, which can be used in conjunction with the most common server-side technologies -- Java, .NET and PHP -- to more esoteric platforms like C, Delphi and Haskell -- all capable of generating JSON-compliant output. A complete list of language specific JSON utilities can be found at JSON homepage .
As far as real world usage is concerned, Yahoo! is one of the leading portal using JSON for Web services , but of course this is not counting the many smaller players, which are already taking advantage of JSON's less bulky syntax to provide an alternate Web service delivery format.
Though using JSON in favor of XML reduces the interoperability advantages inherent in XML, it enhances the overall performance and development effort required to consume services in a browser, not to mention those applications designed around Ajax. If you are on verge of developing Web services and your user base will consist of mostly browser-based clients, give JSON a closer look It provides compelling benefits to what is otherwise considered a default XML Web services response.