I would like to do something like the following but in a more large scale and efficient way. Assume I have an array of objects where each object needs to be leveled/flattened.
Convert something like this ...
[{
name: 'John Doe',
address: {
apartment: 1550,
streetno: 167,
streetname: 'Victoria',
},
}, {
name: 'Joe Smith',
address: {
apartment: 2,
streetno: 111,
streetname: 'Jones',
},
}]
... to that ...
[{
name: 'John Doe',
apartment: 1550,
streetno: 167,
streetname: 'Victoria',
}, {
name: 'Joe Smith',
apartment: 2,
streetno: 111,
streetname: 'Jones',
}]
As is shown above, address
as well is an object which needs to be leveled/flattened.
But most importantly, one does not know the object/data-structure in advance. Thus one neither knows property-names nor the depth of the nested levels.