Wednesday, July 13, 2011

Intro to JSON

In this post I will talk about JSON and its basics. Since it is a main notation language to work with MongoDB.

JSON stands for JavaScript Object Notation.

Like XML JSON is a data interchange format, it is readable by humans and in some aspects better than xml. For example it is more compact and it saves traffic because it has small size whereas xml file can get very large and heavy to transfer over network.

JSON is completely language independent but it is developed on many language concepts that exist in C/C++, python, Java, Javascript, Perl etc...

JSON has two data structures built in.

- Collection of name/value pairs. In other langs this type of collection is realised as  object, record, struct, dictionary, hash table, keyed list, or associative array.

- Ordered list of values. In other langs this is an array, vector, list, or sequence.
These two data structures in JSON can get the form of: object, array, string, value and number.

- Object is an unordered set of name/value pairs. Object begins with "{" and ends with "}". Each name/value pair is separated with other pairs with "," and between name and value always stands ":".

example: object {
                      myName:Vlad,
                      myBlog:tunephp.blogspot.com
               }

-  Array is an ordered collection of values. Array starts with "[" and ends with "]". Values are separated by ",".

example: array[val1,val2,val3]

- Value can be of type string, number, object, array, true, false, null
- String can be any type of string like in other langs.
- Number is a usual number like in other langs (C, Java) except that octal and hexadecimal aren't used.

You might wanna visit the official site JSON . Also dont forget to visit the examples at JSON Examples

No comments:

Post a Comment