Friday, July 4, 2008

JSON - JavaScript Object notation

JavaScript Object Notation is a data interchange format. The JSON format is often used for transmitting structured data over a network connection in a process called serialization. Its main application is in Ajax web application programming, where it serves as an alternative to the traditional use of the XML format.

A simple example is :


This script will popup an alert dialog box with the text 'John.'

The JSON block can support nested types as well as arrays. For example:


{
"firstName": "John",
"lastName": "Smith",
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
"212 555-1234",
"646 555-4567"
]
}


Typically the JSON request will come from the server, or through a Ajax callback or some other technique. This approach is must easier to work with then returning XML that the JavaScript client then has to parse.

No comments: