Is it possible for a JSON array to contain objects with different key/value pairs? The example provided in this tutorial shows objects within the JSON array having the same key/value pair:
{
"example": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Anna",
"lastName": "Smith"
},
{
"firstName": "Peter",
"lastName": "Jones"
}
]
}
If I wanted to change this and have objects with different key/value pairs inside the JSON array, would the following still be considered valid JSON?
{
"example": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"fruit": "apple"
},
{
"length": 100,
"width": 60,
"height": 30
}
]
}
I just want to confirm if this is acceptable. If so, how can I use JavaScript to determine whether the JSON "example"
field contains homogeneous objects (like the first set) or heterogeneous objects (like the second set)?