Iterate array and sum fields in json

Hi,

In the schema I’m working on, I would like to sum up the “price” fields from the json’s in the array “list” and assign the sum to “total”. Any pointers on how to construct the code/formula for it?

{
  "total": 4.37,
  "list": [
    {
      "name": "Miso Paste White",
      "price": 63.64,
    },
    {
      "name": "Paste White",
      "price": 54.93,
    },
}

Thanks you.

Here’s a working example: Mockaroo - Random Data Generator and API Mocking Tool | JSON / CSV / SQL / Excel

It uses a formula and the reduce function:

items.reduce(0) {|total, item| total + item['price']}
1 Like