Search This Blog

Monday, October 5, 2015

JSON Basics

JSON is the abbreviation for  Javascript Object Notation. It's a lightweight data interchange format - Text Format that is independent of any programming language.  It's also a syntax for storing and retrieving javascript objects.

JSON is built on two structures:
1. Name/Value Pairs (something similar to Object in Java)
2. An ordered list of values (something similar to Array in Java)

Example 1:
{"firstName":"venkat", "lastName","chinna"}

Example 2 (Arrays):
"employees": [{"firstName":"venkat", "lastName","chinna"}, {"firstName":"john", "lastName","miller"}]

Example 3 (JSON Object):
"window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    }

Data types:
int, string, float, boolean, array, object, null

JSON vs XML:

JSON
XML
Provides automatic way of serializing/de-serializing javascript objects
Need to write code to do the same.
Format follows simple name/value pairs.
Complex, verbose format with tags and namespaces.
It’s data oriented
It’s document oriented.

No comments: