Skip to navigation | Skip to content

Share your knowledge. Make a difference.

JSON -- Javascript Object Notation

1 - I can do better 2 - Jury's out 3 - Pretty darn good 4 - Splendiferous 5 - Awesometastic (by 3 people)   Your rating: 1 - I can do better 2 - Jury's out 3 - Pretty darn good 4 - Splendiferous 5 - Awesometastic

Ranked #1794 in Tech & Geek, #44701 overall

Rated G. (Control what you see)

JavaScript Object Notation, or JSON, has recently flared into the public consciousness because of one simple fact: it can be used to overcome one of the limitations of Ajax, today's other hot buzzword. Ajax, which relies on HTTP connections from the browser to dynamically update pages without reloading the page, can only make that connection to the server on which the page resides, which makes it difficult to dynamically request, say, a set of results from Yahoo! Web Services.

JSON solves this problem.  Because it provides a way for you to directly create an object in your script dynamically using a script tag, you can use it to, say, add a set of Yahoo data to your page.

Don't forget to check out the "Introduction to JSON" article I've got listed below for the full scoop, including that Yahoo! hack.

Your opinion matters 

Is this lens helpful to you? I'd love to know what you like or don't like about it so I can make it as useful as possible. If you have a moment, please drop me a line and let me know, or simply click the stars above this introduction to let me know how I'm doing. ("Five" is "definitely useful" and "one" is "not even remotely useful, why did I waste my time?".) Thanks!

What is JSON, anyway? 

The first thing we ought to discuss is just what JavaScript Object Notation is, anyway. It is a text-based representation of an object. No more, no less. For example, I might have an object representing a stuffed animal accessed in JavaScript as:

stuffedAnimal.name = "Fluffy";
stuffedAnimal.breed = "Monster";
stuffedAnimal.legs.type = "rubbery";
stuffedAnimal.legs.number = 2;
stuffedAnimal.arms.type = "strong";
stuffedAnimal.arms.number = 5;
stuffedAnimal.texture = "soft";

That's pretty typical Javascript code; I could represent that in JSON as:

{"stuffedAnimal": {"name":"Fluffy",
                    "breed":"Monster",
                    "legs": {
                          "type":"rubbery",
                          "number":2},
                    "arms": {
                          "type":"strong",
                          "number":5},
                    "texture":"soft"}
}

Now, the ability to do that may not seem like much, but it enables you to do two very important things. First, you can dynamically create an object by manipulating the text that represents it, but that's not something most people do. The real key is that it enables you to retreive an object using web services.

And that IS a big deal.

JSON Implementations 

Making it work

Most of the existing implementations are listed on the "official" JSON page, but as I find more, I'll add them here.
The "official" JSON page
This is the canonical information page for JSON. It includes a brief description of the actual format, but is most useful for its links to JSON toolkits in just about every programming language under the sun.
JSON for OpenLaszlo
Apparently OpenLaszlo's implementation of JavaScript has some issues that prevent it from working with JSON Javascript. But never fear, an implementation is here.
sql2json() - Converts SQL Results to JSON String
From the description: "sql2json() converts the result of the given SQL query to its equivalent JSON string. This function will take a SQL query as it argument, execute it, fetch its result and convert it to a JSON string and then return the JSON string."

Get more information on JSON 

Introducing JSON
Also listed above, this is the canonical information page for JSON.
Introduction to JSON
This is the article I referred to in the introduction. It explains what JSON is, how to use it in the browser, and specifically how to use it with a dynamically added <script> tag to add Yahoo data to your page.
Using JSON with Yahoo! Web Services
Several web APIs will return JSON data instead of XML (or in addition to it) but the biggie at this moment is Yahoo! Web Services. This page details how that works.
Using JSON with del.icio.us
Del.icio.us also provides a JSON interface for their web services API. This page is the documentation for that capability.
Project: Javascript Timetracker -- JSON and PHP
This is the first installment of a series of articles describing a Javascript Timetracker that uses JSON to send data back and forth to a PHP page. This article shows you how the PHP part works with JSON.

Blog postings about JSON 

The Technorati JSON tag

One good way to keep up with a topic -- especially a new one, like JSON -- is to see what other people are saying about it. Here are the last six postings that have been tagged as "JSON", according to Technorati.

Loading Fetching RSS feed... please stand by

Books with information on JSON 

JavaScript: The Definitive Guide

Amazon Price: $29.67 (as of 10/07/2008)
List Price: $44.95

Usually ships in 24 hours

Professional Ajax, 2nd Edition (Programmer to Programmer)

Amazon Price: $26.39 (as of 10/07/2008)
List Price: $39.99

Usually ships in 24 hours

Prototype and Scriptaculous in Action [Ajax]

Amazon Price: $29.69 (as of 10/07/2008)
List Price: $44.99

Usually ships in 24 hours

Ajax for Web Application Developers (Developer's Library)

Amazon Price: $24.85 (as of 10/07/2008)
List Price: $34.99

Usually ships in 24 hours

Ajax: The Definitive Guide

Amazon Price: $31.49 (as of 10/07/2008)
List Price: $49.99

Usually ships in 24 hours

X
roadnick

About roadnick

Nicholas Chase is the author of numerous books on web development topics, and the XML and Web Services Reference Guide for InformIT. He has also been involved in Web site development for companies such as Lucent Technologies, Sun Microsystems, Oracle, and the Tampa Bay Buccaneers. Nick has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, and an Oracle instructor. He has written more than 100 tutorials for IBM's developerWorks, and currently works with Backstop Media, which creates custom content for technology companies.

roadnick's Pages

See all of roadnick's pages