Wednesday, July 09, 2008

What is JSON???

If you don't know what JSON is it stands for JavaScript Object Notation and basically looks like this:

{"key":"value", "key2":"value2"}

But you can do so much more: like nesting JSON objects in JSON objects:

{"key":"value", "key2":"value2", "key3":{"nestedKey":"nestedValue"}}

and adding arrays to the JSON Object:

{"key":"value", "key2":"value2", "key3":{"nestedKey":"nestedValue"}, "key4":[{"arrayKey1":"arrayValue1"},{"arrayKey2":"arrayValue2"},{"arrayKey3":"arrayValue3"}]}

With all of those quotes and brackets it gets ugly quick so there is a little python library called simplejson and by simply executing the following line:

print simplejson.dumps(nastyJsonString, sort_keys=True, indent=2)

you get this:

{
  "key": "value",
  "key2": "value2",
  "key3": {
    "nestedKey": "nestedValue"
  },
  "key4": [
    {
      "arrayKey1": "arrayValue1"
    },
    {
      "arrayKey2": "arrayValue2"
    },
    {
      "arrayKey3": "arrayValue3"
    }
  ]
}

 

It is simple but incredibly powerful it is way better than SOAP and shames EJB's and their complexities to no end.

 

If you are doing remoting or communicating between processes of any kind; you should take a look at JSON there are libraries for just about any language you can think of.

 

Cheers!

 

-Aaron

No comments: