10-18-2023 12:46 AM
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
Solved! Go to Solution.
10-19-2023 06:39 PM
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
10-19-2023 06:39 PM
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
10-19-2023 11:05 PM
Thank you @alchemiz this works 🙂