The usage of both can be depended on the structure of your data.
Simply, You can use the Nested Objects approach if you plan to give priority to a unique identifier such as a Primary Key.
eg:
{
"Employees" : {
"001" : {
"Name" : "Alan",
"Children" : ["Walker", "Dua", "Lipa"]
},
"002" : {
"Name" : "Ezio",
"Children" : ["Kenvey", "Connor", "Edward"]
}
}
Or, Use the Array first approach if you intend to store a set of values with no need to identify uniquely.
eg:
[
{
"Employees":[
{
"Name" : "Alan",
"Children" : ["Walker", "Dua", "Lipa"]
},
{
"Name" : "Ezio",
"Children" : ["Kenvey", "Connor", "Edward"]
}
]
}
]
Although you could use the second method with an identifier, it can be harder or too complex to query and understand in some scenarios. Also depending on the database one may have to apply a suitable approach. Eg: MongoDB / Firebase