Array literals
You might be familiar with the name ‘array’ from some other programming language. The thing is that array is a collection of data. In JSON, we can have the array here in JSON. The array here can contain multiple values, which are valid, like the string, number, boolean, object, etc. At times, when we are required to have a collection of data, we would use the arrays. Remember that to use arrays, we have to make use of the square brackets.
Let’s now have a look at a simple example, through which we can understand how can we create arrays.
{
“hobbies”: [“Reading books”, “playing guitar”, “travelling”]
}
or
{
“friends”: [“GyaniPandit”, “John”, “Kevin”]
}
In the above examples, we have an array of hobbies of some individuals, and in the other example, we have an array, which contains the names of friends. Well, this example is individually for the array, so it may not make complete sense, but still, when it is used with some other data, it starts making concrete sense.
So, the thing is that whenever we are required to store a collection of data, we would make use of the arrays. Remember that the array can contain the values that are valid in JSON.