This Angular tutorial helps you get started with Angular quickly and effectively through many practical examples.

JSON Array


1. JSON Array Example

An array is a collection or list of data as defined in other language. An array in JSON is a group of values that are separated by commas. The rules for writing an Array in JSON are as follows.

  • An Array starts with an opening [(Bracket)
  • An Array ends with a closing ](Bracket)
  • Values in the Array are separated by , (Comma)s

Example

In this example, we have created a array qualification inside object. The following example show the simple JSON array:

{
"FirstName" : "Rohatash",
"Age" : "35",
"Address" : "Mathura"
"Qualification" : ["MCA", "BTech", "BCA"]
}

As you can see in the figure below:

Json Array

JSON Array of Numbers: JSON array of Numbers contains number elements only. For example the array below has 5 elements, 23, 44, 76, 34, 98.

[10, 15, 16, 20, 97]

Here, we assign a JSON Array of Numbers to the keynmarks in json Number Array object. Then we access the first element of array using [ ] operator.

{
"FirstName" : "Rohatash",
"Age" : "35",
"Address" : "Mathura"
"Marks" : [10, 15, 16, 20, 97]
}

JSON Array of Objects

A JSON object is similar as JavaScript object. We can also create a JSON Array containing many JSON objects in it, then we can iterate over that array or use the [ ] to get the object we need.

Example

In this example, we have created a array having 3 objects. The following example show the JSON Array of Objects:

{
  "Employee":[
    {"name":"Rohatash", "age":35},    
    {"name":"Gaurav", "age":"30"},  
    {"name":"Rahul", "age":"29"},
  ]
}

Prev Next