Skip to content

#sum

Returns the total of an array of numbers, optionally after a projection.

#sum(array, @x: projection?)
Category Grouping and aggregationValid in Property value
Name Type Description
array path | array The numbers, or elements to project.
projection (optional) lambda Selects the number from each element.

number

source.json
{
"numbers": [ 1, 2, 3, 4 ]
}
transformer.json
{
"result": "#sum($.numbers)"
}
output.json
{
"result": 10
}

Try it in the playground →

source.json
{
"items": [ { "price": 2 }, { "price": 3 } ]
}
transformer.json
{
"result": "#sum($.items, @x: @x.price)"
}
output.json
{
"result": 5
}

Try it in the playground →

#average · #min · #max · #reduce