Jun
3
2009
10 Things To Know About JSON (JSON Javascript Examples)
I used JSON for the first time today and it’s really nothing special. I’ve heard about it a few times but never really given it much thought and theres no reason I should have. Here is the list of all you really need to know about this syntax for passing around name value pairs and arrays to javascript.
- JSON is an acronym for ‘Javascript Object Notation’.
- JSON is fast. Mostly because it is recognized natively by Javascript so there’s no processing overhead.
- JSON is an ordered list of name value pairs.
- JSON is so much easier to read and write than XML due to it’s simplicity.
- Apperently (Untested by me) data is formatted as JSON then Ajax can travel across domains.
- Almost every language used in web development either already has a JSON library or set of functions. If one doesn’t, then creating functions is a trivial task.
- ‘var jsonObject = { ‘cody : ‘taylor’ };’ is referenced by ‘jsonObject.cody’ which gives us ‘taylor’.
- ‘var jsonObect = {‘javascript’ : {‘json’ : ‘not xml’ };’ is referenced by ‘jsonObject.javascript.json’ which gives us ‘not xml’.
- You can also reference the JSON object as if it was an associative array like ‘jsonObject[‘cody’]’ or ‘jsonObject.javascript[‘json’]’ which gives the same values as previously.
- If you don’t want to use key/value pairs you can define a normal data array. ‘jsonObject = {‘arrayOfData’: {‘numbers’ : [‘1’, ‘2’, ‘3’]}};’ We use indexes for this dataset. Don’t use indexes for the collections defined in the ‘{ }’. ‘jsonObject.arrayOfData.numbers[1]’ will give us ‘2’.
- You can put functions in the dataset to pass around executable code.
So now you know basically all there is to know about JSON.