I get an array of objects from an API in the format shown below:
[
{
"participant_details":[
{
"participant_id":2,
"participant_name":"Bond James"
},
{
"participant_id":3,
"participant_name":"Barkley Charles"
}
],
"schedule_details":{
"schedule_id":17,
"schedule_name":"bug test",
"job_type":"Registered Nurse",
"schedule_type":"Shared/Grouped Schedule",
"number_of_shifts":10,
"start_date":"2022-05-30 23:00:00",
"end_date":"2022-06-03 06:00:00"
}
},
{
"participant_details":[
{
"participant_id":3,
"participant_name":"Barkley Charles"
}
],
"schedule_details":{
"schedule_id":18,
"schedule_name":"June Chuk Schedule",
"job_type":"Coordinator - Operations",
"schedule_type":"Individual Schedule",
"number_of_shifts":6,
"start_date":"2022-06-02 09:00:00",
"end_date":"2022-06-07 15:00:00"
}
},
{
"participant_details":[
{
"participant_id":2,
"participant_name":"Bond James"
},
{
"participant_id":3,
"participant_name":"Barkley Charles"
}
],
"schedule_details":{
"schedule_id":19,
"schedule_name":"Grouped Re-assignment test",
"job_type":"People & Culture",
"schedule_type":"Shared/Grouped Schedule",
"number_of_shifts":6,
"start_date":"2022-06-04 19:00:00",
"end_date":"2022-06-10 02:00:00"
}
}
]
The property participant_details contains information about the participants that are attached to the schedule in the property: schedule_details
My question is if there is any way possible to group this data by a participant so that the end result has the schedule_details grouped into an array of objects by participant, somehing that looks like this:
[
{
"participant_id":2,
"participant_name":"Bond James",
"schedule_details":[
{
"schedule_id":17,
"schedule_name":"bug test",
"job_type":"Registered Nurse",
"schedule_type":"Shared/Grouped Schedule",
"number_of_shifts":10,
"start_date":"2022-05-30 23:00:00",
"end_date":"2022-06-03 06:00:00"
},
{
"schedule_id":19,
"schedule_name":"Grouped Re-assignment test",
"job_type":"People & Culture",
"schedule_type":"Shared/Grouped Schedule",
"number_of_shifts":6,
"start_date":"2022-06-04 19:00:00",
"end_date":"2022-06-10 02:00:00"
}
]
},
{
"participant_id":3,
"participant_name":"Barkley Charles",
"schedule_details":[
{
"schedule_id":17,
"schedule_name":"bug test",
"job_type":"Registered Nurse",
"schedule_type":"Shared/Grouped Schedule",
"number_of_shifts":10,
"start_date":"2022-05-30 23:00:00",
"end_date":"2022-06-03 06:00:00"
},
{
"schedule_id":18,
"schedule_name":"June Chuk Schedule",
"job_type":"Coordinator - Operations",
"schedule_type":"Individual Schedule",
"number_of_shifts":6,
"start_date":"2022-06-02 09:00:00",
"end_date":"2022-06-07 15:00:00"
},
{
"schedule_id":19,
"schedule_name":"Grouped Re-assignment test",
"job_type":"People & Culture",
"schedule_type":"Shared/Grouped Schedule",
"number_of_shifts":6,
"start_date":"2022-06-04 19:00:00",
"end_date":"2022-06-10 02:00:00"
}
]
}
]