Arrays in JSON

Arrays in JSON

Now, we are going to have a look at a very simple, interesting, and important data type in JSON, which is an Array. Basically, you might be familiar with the term ‘array’, from some other programming language, but even if this term is completely new for you, do not worry, since we are going to talk about it here.

An array can be simply understood as a collection of data. At times, we are required to have a collection of data with us, like if we are required to have a collection of names of favorite fruits(fruits would be some strings), or we want to have a collection of all the hobbies of some person(hobbies would be some strings). In short, if we are required to have a collection of data, we can make use of the array.

So now, let’s have a look at some of the examples, which demonstrate the arrays.

“favoriteNumbers”:[29, 4, 31, 24],
“favoriteFruits”:[“Kiwi”, “Guava”, “Apple”, “Strawberry”]

You can see in the above example, that we have two arrays, which contain some data, according to the requirements. You can use the arrays inside your JSON file, with the data according to the requirements. But please make sure that the data that you are using in your array, is valid datatype.

You can have an array of booleans, numbers, or objects, or we can also have arrays inside arrays.