I’m receiving the array of JSON objects pasted below from an API call, and would like to reformat it in javascript so that I have a new/simplified array of JSON objects that include:
the attributes in Object1 (just those from ID through City), and the attributes that are in the ‘parent’ object (attributes from q1_response through Notes). I expect I could do with a loop, but was hoping for something more efficient and straightforward.
[
{
"attributes": {
"type": "Survey",
"url": "/xxxx/data/xxxx/xxxx/xxxxx/axxxxxxxxxx"
},
"Object1": {
"attributes": {
"type": "Incident",
"url": "/xxxx/data/xxxx/xxxx/xxxxx/bxxxxxxxxxx"
},
"Id": "aaabbb00001",
"Survey_Version": "V2.0",
"Incident_type": "Call",
"CreatedDate": "2025-04-24",
"Service_Responded": true,
"City": "Houston"
},
"q1_response": "Example q1 response",
"q2_response": false,
"q3_response": false,
"Notes": "Example notes"
},
{
"attributes": {
"type": "Survey",
"url": "/xxxx/data/xxxx/xxxx/xxxxx/axxxxxxxxxx"
},
"Object1": {
"attributes": {
"type": "Incident",
"url": "/xxxx/data/xxxx/xxxx/xxxxx/bxxxxxxxxxx"
},
"Id": "aaabbb00002",
"Survey_Version": "V1.0",
"Incident_type": "Call",
"CreatedDate": "2025-04-26",
"Service_Responded": true,
"City": "Dallas"
},
"q1_response": "Example q1 response",
"q2_response": true,
"q3_response": false,
"Notes": "Example notes"
}
]
Desired outcome:
[
{
"Id": "aaabbb00001",
"Survey_Version": "V2.0",
"Incident_type": "Call",
"CreatedDate": "2025-04-24",
"Service_Responded": true,
"City": "Houston",
"q1_response": "Example q1 response",
"q2_response": false,
"q3_response": false,
"Notes": "Example notes"
},
{
"Id": "aaabbb00001",
"Survey_Version": "V2.0",
"Incident_type": "Call",
"CreatedDate": "2025-04-24",
"Service_Responded": true,
"City": "Houston",
"q1_response": "Example q1 response",
"q2_response": false,
"q3_response": false,
"Notes": "Example notes"
}
]
I tried various versions of filter and reduce, but didn’t get the desired result.


