JSON Objects

JSON Objects

Now, we are going to discuss in greater detail, the objects in JSON. The thing is that object here is going to be the collection of key-value pairs. So, whenever we need to have a collection of key-value pairs in our data, we can make use of objects here. Basically, to write the JSON object, we use curly braces, and it can have multiple key-value pairs. Now, let’s have a look at an example, through which we can understand the object in greater detail.

Points to Remember:

There are some points to remember while we are writing the data here. The keys that we are writing are supposed to be in double quotes, and the values associated with those keys should be of some valid datatype.

Let’s have a look at an example now –

“personName”: “GyaniPandit”,
“age”: 25,
“hobbies”: [“swimming”, “singing”, “reading books”]

As you can see in the above example, you can find that the key-value pairs that we have here, are surrounded by curly braces.

We have some key-value pairs in the object. Remember that the keys here are written in double quotes, and the values associated with the respective keys belong to some valid datatype. Also, since we are having multiple key-value pairs here, the key-value pairs are separated by commas. We have to keep these small things in mind and practice, them because they can make a difference.

So, from this, we can simply understand that the JSON object is going to be a collection/set of key-value pairs.