What is JSON?

JSON Representation

JSON (Javascript Object Notation) is a format in which you represent your data. This format is used to transfer data from server side technologies to client. It is simplest way of representing data. JSON is a key value pair notation of data, for e.g.,


     {"name":"vijay"}
  

where value of the key "name" is "vijay". Similarly you can represent whole lot of data about object whose name is vijay as follows


  {"name":"vijay","id":"1234","location":"bangalore"}
  

If you have one more object whose basic info, you want to send to front end for processing, you can easily encode that data in JSON format as below :

  [{
        "name": "vijay",
        "id": "1234",
        "location": "bangalore"
    }, {
        "name": "XYZ",
        "id": "1233",
        "location": "abcd"
    }]
  

To be more JSON friendly you can embed above array of data in on json key value pair, however this is just for convienience or followed best practice, above mentioned data represents JSON as much as this JSON format

  
 {
    "usersInfo": [{
        "name": "vijay",
        "id": "1234",
        "location": "bangalore"
    }, {
        "name": "XYZ",
        "id": "1233",
        "location": "abcd"
    }]
}
  

Parsing JSON

As name indicates (Javascript Object Notations), JSON objects can be seamlessly accessed and interpreted in Javascript without any hastle. Most of the other programming languages have JSON parser's too which helps in parsing JSON quickly.

Here will consider Javascript scenario, go ahead and open your chrome browser console (press F12 and find console tab).

Copy above JSON data, the one with "userInfo", and in your console type "var userInfo=" (or give any name) and paste JSON object and press enter.

console

Now enter the object name you just now created (userInfo) in cosole and press enter and expand all the arrows, you should see this.

userInfoEntered

Now to access user info array, just type in the object you have created and the key for which you want to access the data, in my case it is

  
userInfo.usersInfo

Output should be like this (expand arrows),
userInfoArray

So to access any key value, you should just put "." and metion key name there.

Similary to access first object you can write

 userInfo.usersInfo[0]

userInfoEnteredFirstObject

To access name of a first object write

  
userInfo.usersInfo[0].name

userInfoEnteredFirstObjectName

Similary you can access other information of JSON objects, like "location", "id" etc..

Let me know if this article helped you or how I can improve this article or any other suggestions in comments section.