{
"workRequestCompleted":[
{
"number":"4329502",
"name":"Scheduled Outage Primary Feeder",
"startDate":"2019-07-01",
"endDate":"2019-07-10",
"lastUpdate":"2019-12-01T05:00:00Z",
"contractId":null,
"status":"Scheduled"
}
],
"prerequisites":[
{
"preq_id":"M12345",
"preq_type":"FLAG",
"preq_date_time":"2019-10-02T03:28:00Z",
"preq_last_update":"2018-12-03T13:30:00Z",
"preq_crew_id_id":"W_FOD_013",
"wr_number":"4329502",
"preq_crew":{
"crew_id":"W_FOD_013",
"crew_name":"Pre-req 1",
"expertise":"Flush"
},
"facilities":[
{
"facility_id":"VS1234",
"facility_type":"VAULT",
"facility_lat":40.758896,
"facility_long":-73.98513,
"facility_notes":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
]
}
],
"workComponents":[
{
"wc_number":"888-FOD-CO-950-609",
"wc_type":"PSMECH",
"wc_description":"Make halves, pick up VS1234.",
"wc_crew_id":"W_FOD_013",
"wc_start_date_time":null,
"wc_end_date_time":null,
"wc_estimated_hours":10.0,
"wc_scheduled_start_date_time":"2020-02-16T19:23:02.866019Z",
"wc_scheduled_end_date_time":"2020-02-17T19:23:02.866028Z",
"wc_actual_hours":0.0,
"wc_status":"Scheduled",
"wc_notes":null,
"wc_number_pre":"888-FOD-CO-178-0",
"wc_number_post":"",
"delay_type":null,
"wr_number":"4329502",
"wc_crew":{
"crew_id":"W_FOD_013",
"crew_name":"Pre-req 1",
"expertise":"Flush"
},
"facilities":[
{
"facility_id":"VS5678",
"facility_type":"VAULT",
"facility_lat":40.758896,
"facility_long":-73.98513,
"facility_notes":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
]
},
{
"wc_number":"888-FOD-CO-178-0",
"wc_type":"PSMECH",
"wc_description":"Make halves, pick up VS1234.",
"wc_crew_id":"W_FOD_013",
"wc_start_date_time":"2019-12-02T04:28:00Z",
"wc_end_date_time":"2019-12-03T13:30:00Z",
"wc_estimated_hours":10.0,
"wc_scheduled_start_date_time":null,
"wc_scheduled_end_date_time":null,
"wc_actual_hours":10.0,
"wc_status":"Pending\n",
"wc_notes":"We noticed that VS5678 may require additional maintenance soon.",
"wc_number_pre":"",
"wc_number_post":"",
"delay_type":"",
"wr_number":"4329502",
"wc_crew":{
"crew_id":"W_FOD_013",
"crew_name":"Pre-req 1",
"expertise":"Flush"
},
"facilities":[
{
"facility_id":"VS1234",
"facility_type":"VAULT",
"facility_lat":40.758896,
"facility_long":-73.98513,
"facility_notes":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
]
}
]
}
I have a JSON object containing arrays. I want to merge the facility arrays with the same facility id from Prerequisites and WorkComponents arrays, creating a new array that contains the facility id and preq_type with wc_type separate by comma if they share the same facility id. How can I achieve this using JavaScript? Thank you.
Expected Result :
[
{
"facility_id": "VS1234",
"type": ["FLAG", "PSMECH"]
}
]