how to create multiple json object inside arrays code example
Example 1: json with multiple objects
{
"cars": {
"Nissan": [
{"model":"Sentra", "doors":4},
{"model":"Maxima", "doors":4},
{"model":"Skyline", "doors":2}
],
"Ford": [
{"model":"Taurus", "doors":4},
{"model":"Escort", "doors":4}
]
}
}
Example 2: json with multiple objects
{
"cars": {
"Nissan": {
"Sentra": {"doors":4, "transmission":"automatic"},
"Maxima": {"doors":4, "transmission":"automatic"}
},
"Ford": {
"Taurus": {"doors":4, "transmission":"automatic"},
"Escort": {"doors":4, "transmission":"automatic"}
}
}
}
data.cars['Nissan']['Sentra'].doors
data.cars['Nissan']['Maxima'].doors
data.cars['Nissan']['Maxima'].transmission
for (var make in data.cars) {
for (var model in data.cars[make]) {
var doors = data.cars[make][model].doors;
alert(make + ', ' + model + ', ' + doors);
}
}