JSON Pros and Cons

Posted on 02/08/2007 , 13 Comments ( Add )

JSON is a simple object serialization approach based on the JavaScript object initializers syntax. The code for initializer (object literal) is put into a string and then interpreted using JavaScript eval() function or JSON parser (which is very lightweight):

serializedObj='{firstName:"john", lastName:"doe"}';
...
// This is just an example, JSON parser should be used instead
// to avoid security vulnerabilities of "eval"
var obj = eval("(" + serializedObj + ")");
document.getElementById("firstName").innerHTML=person.firstName;

JSON is used extensively in various AJAX frameworks and toolkits to provide easy object serialization for remote calls. It is is supported by both GWT and DOJO. There is a growing realization that perhaps JSON should be considered as an option when implementing SOA, for example Dion Hinchcliffe recently published a blog entry suggesting that JSON (and other Web 2.0 technologies) must be seriously considered by SOA architects.

So what are the benefits of using JSON relative to XML (for this comparison I want to focus just on XML and stay away from SOAP)? Here is my brief take on that, there are also numerous other articles and posts on the subjects.

JSON XML
JSON strengths
Fully automated way of de-serializing/serializing JavaScript objects, minimum to no coding Developers have to write JavaScript code to serialize/de-serialize to/from XML
Very good support by all browsers While XML parsers are built-in into all modern browsers, cross-browser XML parsing can be tricky, e.g., see this article
Concise format thanks to name/value pair -based approach Verbose format because of tags and namespaces
Fast object de-serialization in JavaScript (based on anecdotal evidence ) Slower de-serialization in JavaScript (based on anecdotal evidence )
Supported by many AJAX toolkits and JavaScript libraries Not very well supported by AJAX toolkits
Simple API (available for JavaScript and many other languages) More complex APIs
JSON weaknesses
No support for formal grammar definition, hence interface contracts are hard to communicate and enforce XML Schema or DTD can be used to define grammars
No namespace support, hence poor extensibility Good namespace support, many different extensibility options in Schema
Limited development tools support Supported by wide array of development and other (e.g., transformation) tools
Narrow focus, used for RPC only, primarily with JavaScript clients (although one can argue that it's one of the strengths) Broad focus - can be used for RPC, EDI, metadata, you name it
No support in Web services -related products (application servers, ESBs, etc), at least not yet Supported by all Web services products

So the bottom line is that JSON and XML are, of course, two very different technologies; XML is much broader in scope so I'm not even sure if comparing them side by side is fair.

As an object serialization technology for AJAX (or should it now be called AJAJ since we've replaced XML with JSON?) JSON looks very appealing. Anybody who ever tried parsing SOAP directly in a browser (while having to support multiple browsers) can attest that this is not a straightforward task. JSON simplifies this task dramatically. So I think that ESB vendors should definitely start thinking about adding JSON to the list of formats they support.

One of the keys to SOA success is that it should be easy to consume a service, i.e., the entry barrier for service consumers must be low to support "grass root" SOA adoption. While a top-down SOA effort may succeed, it will certainly take longer than bottom-up ("grass-root") approach when developers are able to consume services as they see fit. AJAX/JSON fits this bill perfectly - it is easily understood by developers and it does not require any Web services -specific tools or infrastructure.

So overall I'm pretty enthusiastic about JSON.

13 Responses to “JSON Pros and Cons”

#4624 | February 13th, 2007 | nhm tanveer hossain khan (hasan)

JSON is promising, comparing xml or more complex xml content like soap, json saves a lot of processing pressure. it is a great recuse for the visitor.

#4643 | February 14th, 2007 | Hans

I’ve been wondering about what acronym should be used for “Asynchronous JavaScript and JSON”. But if you write it all out you get “Asynchronous JavaScript and JavaScript Object Notation”, so “JavaScript” is redundant and the phrase can be shortened to “Asynchronous JavaScript Object Notation”. AJON?

Thanks for the writeup!

#4650 | February 15th, 2007 | Raymond

The comparison gave the impression that JSON can only be used with Javascript.
According the author, he defined JSON using javascript but it is a standard that is not confined to Javascript. It is “…a” text format that is completely language independent.”

Go to http://www.JSON.org and read about JSON. Also there are links that answers some of the issues raised in this article.

I am not for or against JSON. XML and JSON both has their own merits. A good developer will pick the best to use for the situation.

#4658 | February 15th, 2007 | Alexander Ananiev

Raymond:
JSON is indeed language independent, however, the balance shifts when you are not using JavaScript – most other languages have very good Web services and XML support, so I’m not sure what would be the use case for JSON, say, in .NET or Java environment. It’s the lack of good XML support in browsers that makes JSON so appealing IMO.

[...] JSON- Some Facts Coming back to JSON, the main fact which goes against JSON is it is not standardized. But now if JSON wants to establish its presence then the only field in my opinion would be SOA web services and AJAX where, it has received a lot of attention. Lately the debate on using web services with JSON has started. XML being heavy puts somewhat a hindrance on the acceptance of web services since the network infrastructure needs to get upgraded to get quicker adoption of XML RPC web services. With JSON, if web services give a higher throughput then it might be time to cash upon its acceptance for data transfer. Alexander writes about JSON pros and cons in his blog MyArch, One of the keys to SOA success is that it should be easy to consume a service, i.e., the entry barrier for service consumers must be low to support “grass root” SOA adoption. While a top-down SOA effort may succeed, it will certainly take longer than bottom-up (”grass-root”) approach when developers are able to consume services as they see fit. AJAX/JSON fits this bill perfectly – it is easily understood by developers and it does not require any Web services -specific tools or infrastructure.So overall I’m pretty enthusiastic about JSON. [...]

#24355 | March 10th, 2008 | Sharath

Does Json webservice allow List or arrays having more elements within them as members of a return type List

#34814 | December 18th, 2008 | Prashant Joshi

Every technology has its own merits and de-merits. As per my experience, JSON is good for sending small information over http. when use along with REST, it offers lots of flexibility, specially when working in cross technology domain.

#35213 | February 28th, 2010 | ANURAG SHARAN

EXCELLENT BASICS MATERIAL.. GOOD STUFF FOR BEGINNERS

#35372 | November 25th, 2010 | carlos

its all about saving hardware and performance resources… time consuming and a lot of stupid questions.
hardware is evolving every day its all concerns about performance could be obsolete soon.

#35400 | June 20th, 2011 | Enabling collaboration with open APIs

[...] and straightforward integration models that are easy to understand, use, and adopt. For example, JSON andREST are common models today that encourage both simplicity and high performance. But it’s not [...]

#35417 | September 28th, 2011 | JSON | ramprasadm

[...] http://myarch.com/json-pros-and-cons –> [...]

#35425 | October 11th, 2011 | Binod

good article.

#35528 | December 9th, 2011 | Anish Sahare

Respected sir

I have to insert json object into oracle table using procedure .
for this purpose plz let me know what process should i follow is there any need to include some package and from where i can get that

if you have sample example for json object insertion in oracle .
so plz send it to my mail(sahareanish@gmail.com) or as a reply in this forum.

(this is my edited question my only and very clear motto is that i want to insert JSON object in Oracle table)

Many Thanks in Advance

Anish Sahare

Leave a Reply

Name

Mail

Website

Your Comment