RSS
 

Archive for the ‘XML’ Category

What is “JSON” and what does it have to do with distributed computing?

02 Jul

JSON” stands for “JavaScript Object Notation” and is an efficient way to transfer complex information about specific entities between two separate programs.

As the “JavaScript” name implies, JSON is often used to transfer information between JavaScript-interpreting web browsers and JSON-aware web applications.  In fact, native understanding of JSON is now built into most web browsers’ JavaScript interpreters.

However, JSON is also implemented (as of June 2010) in about 50 other languages using more than 100 tested libraries.  Furthermore, the specification is short and elegant enough for any reasonably competent programmer to build his or her own JSON parser in relatively short order.

JSON can be used to represent primitive data types, such as one integer (e.g., “1”) or one string (e.g., “fred”), but JSON is more frequently used to represent complex data including specifically named attributes (e.g., “color=blue, ID=342…”), arrays of values (e.g., “7,6,8…”) or even arrays of attributes.

Let’s take a look now at a simple JSON sample.  This is a record that describes a complex data structure: a person.

{
  "firstName": "Elwood",
  "lastName": "Blues", 
  "SSN": 111-11-1111,
  "address": {
    "addressLine1": "1060 West Addison St.",
    "addressLine2": "Suite 1313",
    "city": "Chicago",
    "state": "IL",
    "postalCode": "60613"
  },
  "autoViolations": [
    { "type": "speeding", "amount": "145.25" },
    { "type": "parking", "amount": "15.00" }
  ]
}

There are three simple objects (“firstName”, “lastName”, “SSN”), each of which is made up of a name/value pair of strings.   There is also a complex object (“address”), which is itself made up of 5 simple objects and a second complex object (“autoViolations”), which contains an array of similar objects.

Veterans of XML will note that this same data structure could easily be represented in XML, but JSON advocates favor JSON over XML because:

  • JSON does more with fewer characters (e.g., XML “<repeats></repeats>” the names of keys)
  • JSON maps more cleanly into major programming languages than XML (almost all languages have strings, numbers and object/class and array data structures)
  • JSON does not stray into the “can also be used to display data” camp like XML does (with XSLT transformation) because JSON is not a document markup language

JSON has a couple of years to go before it catches up with XML in popularity among the general programming community, but JSON has clearly leapt out in front with cutting edge programmers working on state-of-the-art presentation frameworks such as Qooxdoo or highly distributed databases such as Cassandra.

As these better presentation frameworks and more distributed computing concepts work their way into the mainstream, JSON’s use and relevance will only increase.

 
Comments Off

Posted in Cassandra, Introduction, JSON, XML