10-25-2023 03:34 AM
I have an array of the following form:
I want to convert this array of objects into a single object that has the same fields along with Debit_Amount and Credit_Amount fields summed up.
Any help is appreciated!
Solved! Go to Solution.
11-29-2023 12:26 PM
@vgautam64 - I believe this solves your question in the simplest way I can think of. Use a Mapper snap with the following configuration:
It appears to me that you only need the field elements and values from the first group element: $group[0]
The two jsonPath statements are simply pulling all values for the Debit and Credit Amounts into an array of numbers
Finally, the Array.reduce() method is used to aggregate that list of numbers into a final total.
Hope this helps!
10-27-2023 12:47 AM
Hi @vgautam64 ,
Try the following expression in a mapper:
$group.reduce((acc,curr,ind)=> acc.extend(curr.mapKeys((val,key)=>key+ind)),{})
Let me know what you think.
Regards,
Bojan
11-29-2023 12:26 PM
@vgautam64 - I believe this solves your question in the simplest way I can think of. Use a Mapper snap with the following configuration:
It appears to me that you only need the field elements and values from the first group element: $group[0]
The two jsonPath statements are simply pulling all values for the Debit and Credit Amounts into an array of numbers
Finally, the Array.reduce() method is used to aggregate that list of numbers into a final total.
Hope this helps!
12-05-2023 03:03 AM
@koryknick Thank You! This worked out for me pretty well.