Sunday, September 27, 2009

JSON is JavaScript Object Notation (Pronounced as Jason)


JSON is a lightweight computer data interchange format. It is a text-based, human-readable format for representing simple data structures and associative arrays (called objects).

The JSON format is specified in RFC 4627 by Douglas Crockford. This 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 use of the XML format.

The following example shows the JSON representation of an object that describes a person. The object has string fields for first name and last name, contains an object representing the person's address, and contains a list of phone numbers (an array):
{
     "firstName": "John",
     "lastName": "Smith",
     "address": {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": 10021
                },
     "phoneNumbers": {
         "212 555-1234",
         "646 555-4567"
                      }
}

Although JSON was based on a subset of the JavaScript programming language (specifically, Standard ECMA-262 3rd Edition-December 1999) and is commonly used with that language, it is considered to be a language-independent data format. Code for parsing and generating JSON data is readily available for a large variety of programming languages. The http://json.org website provides a comprehensive listing of existing JSON bindings, organized by language.

Although JSON is intended as a data serialization format, its design as a subset of the JavaScript programming language poses several security concerns. These concerns center on the use of a JavaScript interpreter to dynamically execute JSON text as JavaScript, thus exposing a program to errant or malicious script contained therein - often a chief concern when dealing with data retrieved from the internet.

No comments: