In this article let us take a look at how JSON and the data stored within an array interact with each other.
|JSON Array Datatypes|
JSON Array Structure
To declare a JSON array, the “[ ]” brackets are used, with the items being stored inside the brackets. See the example below:
Adding multiple items
To add multiple items into the array, “, ” is used between the two items which will separate them from each other. Check out the example below:
Different from many other languages, a single JSON array can contain elements of many different datatypes as shown below:
Inside a JSON document, many different operations can be performed on the array. Take a look at the sample JSON document below:
"name" : "Harris",
"gender" : "M",
"age" : 22,
"hobbies" : [ "cricket", "painting", "gaming" ]
To retrieve a value from a JSON array, follow this syntax and store into a variable:
To perform deletion on any value in a JSON array, use the “delete” keyword as the sample below suggests:
To update any current value of the array, simply use the index number and assign it a new value as shown below:
These are the most important properties of a JSON array. This article is a useful manual on how to use arrays inside JSON code.