I am working with a nested array of objects, shown below:
[
{
"i18n Key": "messages.titles.info",
English: "Info",
Spanish: "Info",
},
{
"i18n Key": "messages.titles.export",
English: "Export",
Spanish: "Exportar",
},
{
"i18n Key": "messages.common.pleaseWait",
English: "Please Wait…",
Spanish: "Por favor esperar…",
},
{
"i18n Key": "messages.common.errors.couldNotAccessADGroup",
English: "Could not access AD to get user groups. Please try again.",
Spanish: "No se puede acceder a AD para buscar grupos de usuarios. Por favor inténtelo nuevamente.",
},
{
"i18n Key": "labels.country.regulatorList.regulatorForm.regulatorName",
English: "Regulator Name",
Spanish: "Nombre del regulador",
},
{
"i18n Key": "labels.country.regulatorList.regulatorForm.country",
English: "Country",
Spanish: "País",
},
]
How can I transform this into a nested object structure like the one below?
{
"messages": {
"titles": {
"info": "Info",
"export": "Exportar",
},
"common":{
"pleaseWait": "Por favor esperar…",
"errors": {
"couldNotAccessADGroup": "No se puede acceder a AD para buscar grupos de usuarios. Por favor inténtelo nuevamente.",
}
},
}
"labels":{
"country":{
"regulatorList":{
"regulatorForm":{
"regulatorName": "Nombre del regulador",
"country": "País",
}
}
}
}
}
The length of the "i18n Key" varies and it is based on the last word. The corresponding Spanish value should be retained.
Any assistance on achieving this would be highly appreciated.