Tuesday, June 24, 2008

Understanding JSON

Some pple get scared when they see strange words like JSON. But if you take a closer look they are nothing ;). So here is a basic guide for JSON. JSON stands for JavaScript Object Notation. Also remember there is no "A" in between J and S ;P.
Here is a simple JSON object
{name:'Dilan'}

There is another way to write this
{'name':'Dilan'}

Both are same. Then how do we use JSON in javascript? Answer is pretty simple... here it is..
var person={'name':'Dilan'};
alert(person.name);

Done! That is it. Wait a sec how about if a person have many interests.. that needed to be represented in an array.. ok! here we go
var person = {'name':'Dilan', 'interests':['watch movies','play crickets','code']}

who la! We are done! So this should be a good foundation for you to start! Next time when your fellow developer or interview board ask for a JSON don't freak out! Just hit them back with a good example! cheers!!!

1 comment:

Gaveen said...

The part where I freak out would be JavaScript not JSON :) because JSON feels (and considered) much like YAML