In this tutorial, I am going introduce you about JSON Array. JSON Array is similar to Array in Javascript as it stores the value of different type as string number, Boolean, object as an array.

Introduction:

JSON Array is similar to Array in JavaScript as it can store the value of different types such as string number, Boolean, object as an array.

“[“ is used to represent JSON array and comma is used to separate JSON array value.

JSON array

JSON Array of String Type:

See the below example to declare JSON array of String Type.


[“C#”,”Java”,”C”,”C++”,”PHP”,”Javascript”];

JSON Array of Number Type:

See the below example to declare JSON array of String Type.


[2,4,6,8,10,12];

JSON Array of Boolean Type:

See the below example to declare JSON array of String Type.


[true,false,false,true];

JSON Array of Object  Type:

See the below example to declare JSON array of Object Type.


{

“Employees”:[

{

“FirstName”:”Sohail”,”LastName”:”Khan”,”Age”:40,”Address”:”New Delhi”

},

{

“FirstName”:”Ritwik”,”LastName”:”Joshi”,”Age”:30,”Address”:”Mumbai”

},

{

“FirstName”:”Kiran”,”LastName”:”Kumar”,”Age”:40,”Address”:”Agra”

}},

{

“FirstName”:”Ayush”,”LastName”:”Singh”,”Age”:40,”Address”,”Agra”

}

]


}

Nested Array in JSON object


{

“Employees”:[

{

“FirstName”:”Sohail”,”LastName”:”Khan”,”Age”:40,”Address”:”New Delhi”,”Skill”:{

[

“Web Development”,

 “Software Testing”

]

}

},

{

“FirstName”:”Ritwik”,”LastName”:”Joshi”,”Age”:30,”Address”:”Mumbai””,”Skill”:{

[

“Web Development”,

 “Software Testing”

]

}

},


{

“FirstName”:”Kiran”,”LastName”:”Kumar”,”Age”:40,”Address”:”Agra””,”Skill”:{

[

“Web Development”,

 “Software Testing”

]

}

}},


{

“FirstName”:”Ayush”,”LastName”:”Singh”,”Age”:40,”Address”,”Agra””,”Skill”:{

[

“Web Development”,

 “Software Testing”

]

}

}

]


}

How to Access JSON Array value?

You can access the item in JSONArray using the index as you do in a simple array.


varFirstName=myobj.Employees[0].FirstName;

How to Loop through JSON Array?

For(variCount=0;iCount<objEmployees.Employees.length;iCount++)

{

var Employee=objEmployees.Employees[iCount];

}

View More:

Conclusion:

Hope you understand this small post about JSON array. I would like to have your Feeback, Comments and Suggestions.

Thank You.

Leave a Comment