Array in JSON

Advertisements

Prev Tutorial Next Tutorial

Array in JSON

In JSON array are declare inside square brackets. Some like JavaScript, a JSON array can contain multiple objects.

Example

"employees":[
    {"firstName":"Komal", "lastName":"Pandit"}, 
    {"firstName":"Ajay", "lastName":"Jain"}, 
    {"firstName":"Hitesh","lastName":"Kumar"}
]

In the example above, the object "employees" is an array containing three objects. Each object is a record of a person (with a first name and a last name).

Declare array in JSon

Example

var employees = [
    {"firstName":"Komal", "lastName":"Pandit"}, 
    {"firstName":"Ajay", "lastName":"Jain"}, 
    {"firstName":"Hitesh","lastName":"Kumar"}
];

Access Data for array in JSON

First way

employees[0].firstName + " " + employees[0].lastName;
// returns Komal Pandit

Second Way

employees[0]["firstName"] + " " + employees[0]["lastName"];
// returns Komal Pandit

Modify Data of array in JSON

First way

employees[0].firstName = "Kajol";

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements