JensDeveloper
3 years agoContributor II
Transform values of a key into an object with list of the value
Hi,
So I am trying to change my json data in a way that we have a list of companies that show every record with the name of the company in an object with the required fields
My input:
{
"companies":{
"CURRENT_COMPANY_DISPLAY_NAME":"test1",
"Code":"123",
"Company_Legal_Name":"test1 nv",
"Company_Name":"test1 x",
"Country":"Germany"
}
},
{
"companies":{
"CURRENT_COMPANY_DISPLAY_NAME":"test2",
"Code":"456",
"Company_Legal_Name":"test2 NV",
"Company_Name":"test2 x",
"Country":"Belgium"
}
}
My requested output:
{
"companies": {
"test1": {
"Code": "123",
"Company_Legal_Name": "test1",
"Company_Name": "test1 nv",
"Country": "germany",
},
"test2": {
"Code": "456",
"Company_Legal_Name": "test2",
"Company_Name": "test2 nv",
"Country": "belgium",
}
}
} I have tried the mapping of the values and the keys but haven't got really further yet.
Regards
Jens
Hi JensDeveloper ,
Good day, hope this helps 😊$.map(c=> sl.ensureArray(c['companies']['CURRENT_COMPANY_DISPLAY_NAME']).toObject((x,y)=> x, (x,y)=> c.get('companies').filter((v,k)=> k != 'CURRENT_COMPANY_DISPLAY_NAME')))~EmEm