Why JSON is Important to You!

What is JSON?

JSON stands for JavaScript Object Notation. (JSON is pronounced like the name Jason)

It is a data format. (XML is also a data format)

The JSON data format is ideally suited for consumption by a JavaScript program. (In fact, JSON is JavaScript!)

Why Should I Care About JavaScript?

Because Ajax applications use JavaScript. (And because JavaScript is very cool)

But Ajax Applications Can Process Data Formatted as XML, so Why Bother With JSON?

If the data is formatted as XML then Ajax is limited to fetching data from the same domain (website) that the Ajax application came from.

If the data is formatted as JSON then Ajax can travel across domains. That is, Ajax can access data from anywhere. Think of the power of this: a single Ajax application, running in your browser, can reach out and grab data from an unlimited number of web services, and present it in your browser in a coherent fashion. Awesome!

What Does JSON Look Like?

Here's information about a person, his website, and his email, all structured as JSON:

{"person": {
     "name":    "John Doe",
     "website": "http://www.example.com/",
     "email":   "jdoe@example.com"
   }
}

How is the Data in JSON Extracted?

Very easy: (suppose the variable "data" holds the above JSON data)

data.person.name       returns "John Doe"
data.person.website    returns "http://www.example.com"
data.person.email      returns "jdoe@example.com"

Are There Web Services That Serve Up JSON?

Yes. For example, all of Yahoo's Web Services can return JSON if it's requested. Here's an example:

http://api.search.yahoo.com/NewsSearchService/V1/newsSearch?appid=xyz&query=Obama&output=json

Should My Web Service Serve Up JSON?

I think that it would be good for your web service to be capable of serving up both XML and JSON. You might implement it in the same way Yahoo does, e.g.

http://www.example.com/web-service?output=json
http://www.example.com/web-service?output=xml

Who Discovered JSON?

JSON is the brainchild of Douglas Crockford, one of the preeminent JavaScript coders in the world today (http://www.crockford.com).

Where Can I Get More Info?

See the excellent book: Bulletproof Ajax, by Jeremy Keith, p. 77-87


Tags

Last Updated: April 6, 2008