Is it possible to determine if a value in a JSON key's value is an array without prior knowledge of the key's name? There are two potential formats for the JSON object:
{
"person": [{
"id": "1",
"x": "abc",
"attributes": ["something"]
},
{
"id": "1",
"x": "abc"
}
]
}
In order to parse this data effectively, I need to be able to detect whether the value of the key is an Array or just a singular value. This needs to be done without knowing the specific name of the key (for example, "attributes" in the provided code snippet). The challenge also lies in looping through all "person" objects and their respective keys.
I have come across a solution that works when the key name is known and there is only one "person" object. However, I am unsure of how to adapt this approach when dealing with multiple "person" objects and not knowing the key names.
if (Array.isArray(json.person['attributes'])) // assuming json holds the parsed JSON content
{
}