Summing up a field from the innermost JSON node and displaying the total in the outermost node

How do we modify the formula if we have to sum up the values at 3 levels.

Tried something like serviceline.productgroup.map {|l| l[‘amount’]}.sum and serviceline.productgroup.map {|l||l| l[‘amount’]}.sum Both these did not work.

If the syntax could be explained that would be helpfull.