JSON

The educational technology and digital learning wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Definition

“JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.” (JSON, retrieved 19:07, 15 May 2007 (MEST)).

JSON (JavaScript Object Notation) is a lightweight computer data interchange format. It is a text-based, human-readable format for representing objects and other data structures and is mainly used to transmit such structured data over a network connection (in a process called serialization). JSON finds its main application in AJAX web application programming, as a simple alternative to using XML for asynchronously transmitting structured information between client and server.” ([1], retrieved 19:07, 15 May 2007 (MEST))

Technology

  • JSON is one of the rare modern data-interchange formats that is not XML.

JSON is a subset of the object literal notation of JavaScript. Since JSON is a subset of JavaScript, it can be used in the language with no muss or fuss.


JSON supports several data types including:

  • number (integer, real, or floating point)
  • String (double-quoted Unicode with backslash escapement)
  • boolean (true and false)
  • Array (an ordered sequence of values, comma-separated and enclosed in square brackets)
  • Object (collection of key/value pairs, comma-separated and enclosed in curly brackets)
  • null (Rob Gravell, retr. feb 2008)
 { 
   "anInt": 5555, 
   "aFloat": 55.055, 
   "aString": "testing", 
   "aBoolean": true, 
   "anArray": [1, "2", 3.34, "dog"], 
   "anObject": { 
           "prop1": "a value", 
           "prop2": "another value", 

"prop3": -9999 }, "aNull": null

}

JSON is built on two structures (JSON website, retr. May 2007):

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
var myJSONObject = {"bindings": [
       {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
       {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
       {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
   ]
};

In this example, an object is created containing a single member "bindings", which contains an array containing three objects, each containing "ircEvent", "method", and "regex" members.

Members can be retrieved using dot or subscript operators.

 myJSONObject.bindings[0].method    // "newURI"

Links

Official
Tutorials and Overviews