I am trying to combine the following arrays based on a matching field "employerPayeReference" of the below arrays
Array 1:
{
"employments": [
{
"employerPayeReference": "123/AB456",
"payFromEmployment": 100.00
},
{
"employerPayeReference": "456/AB456",
"payFromEmployment": 100.00
}
]
}
Array 2:
{
"employments": [
{
"employerPayeReference": "123/AB456",
"taxTakenOffPay": 10.00
},
{
"employerPayeReference": "456/AB456",
"taxTakenOffPay": 15.00
}
]
}
How can I arrive at an array that looks like this
{
"employments": [
{
"employerPayeReference": "123/AB456",
"payFromEmployment": 100.00
"taxTakenOffPay": 10.00
},
{
"employerPayeReference": "456/AB456",
"payFromEmployment": 100.00
"taxTakenOffPay": 15.00
}
]
}
(i.e) it is combined based on the employerPayeReference matching. Any help appreciated