I have a JSON structure that needs to be reformatted in order to meet the requirements of an external service. Although the current format is complex and cannot be altered, I need to modify it to match the desired output for the external service.
Current JSON:
{
"specifiers": [{
"value": "test",
"type": "text",
"label": "Brand ID"
}, {
"value": "test",
"type": "text",
"label": "Program ID"
}]
}
Desired Output:
{
"specifiers": {
"Brand ID": {
"text": {
"value": "test",
"type": "text"
}
},
"Program ID": {
"text": {
"value": "test",
"type": "text"
}
}
}
}
I have attempted to iterate through the existing JSON data using loops, but am struggling with how to properly use the values as keys. I believe I may need to utilize Object.keys or Object.values, but I am unsure of how to access specific values based on their corresponding keys.
Example Format:
"[label]": {
"[type]": {
"value": [value],
"type": [type]
}
}