I want to merge two same keys in an array and get the sum of the values. I want the same structure as it is now.Because this data needs to be converted to JSON.
This is what i get now.
{ "data": [{ "count_of_invites": 5, "user": "Rajesh", "id": "53" }, { "count_of_invites": 9, "user": "Student", "id": "45" }, { "count_of_invites": 4, "user": "Student", "id": "45" } ] }
As you can see the id 45 are repeated.As i want the result as,
Expected output { "data": [{ "count_of_invites": 5, "user": "Rajesh", "id": "53" }, { "count_of_invites": 13, "user": "Student", "id": "45" } ] }
As you can see the duplicate entry should be removed as well as the count_of_invites of duplicate entry should be added.