JSON Objects

JSON Objects are written with key/value pairs and surrounded by curly braces{} and keys and values are separated by colon : and each key/value pair is separated by a comma ,.

We can access the object values by using dot . notation and also access by using brackets [] notation.

Below an example to create an empty object.

var jsonObj = {};

Example #1.

var jsonObj = {"name":"Saarthak Singh","age":"20"}

Access a JSON object using dot . notation:

jsonObj.name // Saarthak Singh

Access a JSON object using bracket [] notation:

jsonObj["name"] // Saarthak Singh