This topic will be a continuation of this thread: Format object with some keys to array
The problem is more complex and I tried to match the current solutions, unfortunately without success.
It receives from the database this format:
const response = [
{
short: 'en',
value: 'John Smith',
path: [
'person',
'add-22da-da-8c93-dae11e',
'firstname'
]
},
{
short: 'en',
value: {
'29ca6xx-5200-3d45-aad2-2da4dddadad': {
name: 'Marianna',
content: 'Person 1',
},
'66fdsfdsf-da22-ada-rrd-uuid21131': { name: 'Josh' },
'rr433d-a21d-aaadd-uuid-sas333dd': {
name: 'Elizabeth',
otherkey: 'Seventy',
},
'uuid21e1-dda-da2211-dad2-gfhfyfyf': {
data: {
0: { name: 'Adrian' },
},
},
},
path: [ 'items', '*' ]
},
];
And I have to parse it in such a way to get exactly that result:
[
{
short: 'en',
value: 'John Smith',
path: 'person.add-22da-da-8c93-dae11e.firstname'
},
{
short: 'en',
value: 'Marianna',
path: 'items.29ca6xx-5200-3d45-aad2-2da4dddadad.name'
},
{
short: 'en',
value: 'Person 1',
path: 'items.29ca6xx-5200-3d45-aad2-2da4dddadad.content'
},
{
short: 'en',
value: 'Josh',
path: 'items.66fdsfdsf-da22-ada-rrd-uuid21131.name'
},
{
short: 'en',
value: 'Elizabeth',
path: 'items.rr433d-a21d-aaadd-uuid-sas333dd.name'
},
{
short: 'en',
value: 'Seventy',
path: 'items.rr433d-a21d-aaadd-uuid-sas333dd.otherkey'
},
{
short: 'en',
value: 'Adrian',
path: 'items.uuid21e1-dda-da2211-dad2-gfhfyfyf.data.0.name'
}
]
This is such a difficult parser to write that it’s not really clear how many subkeys there are of this object and how nested it is. In any case, I always have to get the result in the format I wrote above.
I’ve tried a great many combinations of map, object.keys, for loop functions but I just give up.