Javascript - JSON (JavaScript Object Notation)

1 - About

JSON stands for JavaScript Object Notation. It is a simple format for representing nested structures of data (lists of lists of dictionaries, …).

JSON is basically a specific syntax for organizing data as JavaScript objects.

JSON (JavaScript Object Notation), specified by RFC 4627, is a lightweight data interchange format based on a subset of JavaScript syntax (ECMA-262 3rd edition).

JSON (Javascript Object Notation) has an obvious advantage over XML in that the response is lightweight. Parsing such a result is trivial in JavaScript as the format is already a valid Javascript object.

3 - Example

3.1 - Json variable declaration with a function

// a variable
var debug = {  
     // a property
     debug : true,   
     // a function
     console : function(str) {  
        if (debug) {
            console.log(str);
        }
     }  
}
// we call the function  
debug.console("Log this"); 

4 - Library

4.1 - Java: Org.Json

org.json Parses a JSON (RFC 4627)

String json = "{"
         + "  \"query\": \"Pizza\", "
         + "  \"locations\": [ 94043, 90210 ] "
         + "}";
 
 JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
 String query = object.getString("query");
 JSONArray locations = object.getJSONArray("locations");

5 - Documentation / Reference

  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at del.icio.us
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at Digg
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at Ask
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at Google
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at StumbleUpon
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at Technorati
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at Live Bookmarks
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at Yahoo! Myweb
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at Facebook
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at Yahoo! Bookmarks
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at Twitter
  • Bookmark "Javascript - JSON (JavaScript Object Notation)" at myAOL
javascript/json.txt · Last modified: 2016/04/02 19:55 by gerardnico