Sum JSON values

In my scenario I make multiple HTTP requests and get multiple JSON in answers. JSON look like:

{"results":[{"visitors":123,"target":"AAA"},{"visitors":45,"target":"BBB"},{"visitors":11,"target":"CCC"}]}

How to SUM them all and get info about total visitors on targets from multiple HTTPS responses at the end e.g.

AAA - 1000 visitors
BBB - 500 visitors
CCC - 70 visitors

?

numerical aggregator for the win!

Numerical aggregator

A numerical aggregator lets you to apply functions like SUM or AVG to numerical values. Numerical aggregator then returns the results in one bundle.

1 Like

I’m trying to use Numerical aggregator, but I can’t aggregate them by the “target” in this JSON structure.

One of HTTP request give me 0 result, another 5, and another one 20. The order is random. I can’t group (and sum) all them by “target”.

Anyone knows how to do it?

You’ll need to use map() to create a new structure first and then use the numerical aggregator.

1 Like