Welcome!

Kurt Cagle

Subscribe to Kurt Cagle: eMailAlertsEmail Alerts
Get Kurt Cagle via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: RIA Developer's Journal, AJAX World RIA Conference

RIA & Ajax: Article

Real-World AJAX Book Preview: A Brief Note on JSON

Real-World AJAX Book Preview: A Brief Note on JSON

This content is reprinted from Real-World AJAX: Secrets of the Masters published by SYS-CON Books. To order the entire book now along with companion DVDs for the special pre-order price, click here for more information. Aimed at everyone from enterprise developers to self-taught scripters, Real-World AJAX: Secrets of the Masters is the perfect book for anyone who wants to start developing AJAX applications.

A Brief Note on JSON
The object notation used by JavaScript has made its way into a way to transmit structure better in a number of different languages. JSON (JavaScript Object Notation) has gained a fair amount of interest as a somewhat lighter-weight alternative to XML, especially when used across pipes for AJAX transmission.

In essence, the idea is that you can serialize any object's state as a hash of other objects, each of which can also be broken down as a hash of either other objects or primitives. For instance, you could create a JSON object of a person's record, including his address:

var rec = {identity:{ firstName:"Aleria", surName:"Delamare", gender:"female"},
address:{ street: "1234 Fairmont Drive", city:"Arkham", state:"MA"}, display:
function(){alert(this.identity.firstName +" " + this.identity.surName);} }

The advantage of JSON is that when transmitted, such objects can be reconstructed easily (especially if going from a JavaScript environment to a JavaScript environment) without specialized parsers. The disadvantage of JSON is that it doesn't necessarily transmit state as effectively as XML does in heterogeneous environments. However, a significant number of AJAX applications now routinely make use of JSON as their primary serialization method, especially for client-to-client communications.

Summary
I've tried the near impossible in this (loooong) chapter - covering the highlights of JavaScript in a single chapter of a book. It was, at best, only a partially successful endeavor, as there are obviously many, many elements that could have been covered in greater detail (date manipulation, for instance) that weren't for lack of space. However, if all that had been covered, this would have been a book on JavaScript basics, not the power and beauty of AJAX.

This chapter has focused on the client application, but AJAX also has a fairly formal server-side requirement. In Chapter 3, the server-side components of AJAX will be explored in greater detail, showcasing how AJAX is not only a rich client application but actually a design methodology for changing the role of both client and server.

This content is reprinted from Real-World AJAX: Secrets of the Masters published by SYS-CON Books. To order the entire book now along with companion DVDs, click here to order.

More Stories By Kurt Cagle

Kurt Cagle is a developer and author, with nearly 20 books to his name and several dozen articles. He writes about Web technologies, open source, Java, and .NET programming issues. He has also worked with Microsoft and others to develop white papers on these technologies. He is the owner of Cagle Communications and a co-author of Real-World AJAX: Secrets of the Masters (SYS-CON books, 2006).

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.