What is JSON??
JSON (JavaScript Object Notation) is a lightweight data-interchange format based on object notation of the JavaScript language. JSON is completely language independent but uses all conventions of all C-family languages like C++, C#, Java, PERL, Python and many others thus makes it idyllic for data-interchange between two diversified components.
JSON is built on two structures:
1. A collection of name/ value pairs. In many languages this is recognized as an object, record, struct, dictionary or hashtable.
2. An Ordered List of values like array, sequences, Vector or a list.
As mentioned above JSON is data-interchange Format, now question arises is why we need JSON when we have data interchange format like XML, CSV exists which supports for all features starting with Data exchange property till Data serializability between interoperable components. Answer is simple why we need a heavily required parsed data format in the world of Objects. XML requires heavy parsing at all ends.XML is something like where data is warped into some angle brackets at the transmitting end and you need to unwrap data at the consuming end. After this process is done you need to assign that parsed data for your internal use. Why can’t we have a simple format between 2 AJAX communicating ends? Since today, Ajax is widely used to get data from server time to time in many web applications. And the Answer is JSON. JSON can be considered as an object which is native to JavaScript which requires no parsing at any JavaScript Client end If browser. Thus, splendors the demand of building RIA (Rich Internet Application) clients.
Example of JSON for object Person:

Corresponding XML:

What is JSONRequest??
Recently, I came across with the Article by Douglas Crockford, the pioneer at yahoo motivating mortals to develop browsers with JSONRequest object just like XMLHttpRequest but will work for JSON format. The epitome of JSONRequest is based on requirement of next generation web applications which will be more data intensive. The link provides more about it (http://www.json.org/JSONRequest.html). And the code will look like this.
requestNumber = JSONRequest.post(
"https://json.penzance.org/request",
{
user: "doctoravatar@yahoo.com",
t: "vlIj",
zip: 94089,
forecast: 7
},
function (requestNumber, value, exception) {
if (value) {
processResponse(value);
} else {
processError(exception);
}
}
);
Furthermore Douglas’s explains with nice comment “JSON is the X in Ajax” on AJAX and role of JSON in ajaxifying web applications for secure and efficient use. And that’s Boolean true if we consider ability of JSONRequest Object to make fast (compared to XML) Asynchronous call to server equated with XMLHttpRequest. For XMLHttpRequest, parsing is required plus one need to consider the DOM part as well. Whereas JSON format and JSONRequest makes life easier thereby fortifying the motive of AJAX which is considered to be a needy practice for building typical Web 2.0 Applications.
0 comments:
Post a Comment