0

I am Trying to make a sum in Json Array with Jolt but i did not succeess.

This is my json :

[
  {
"times-entries": {
  "offset": 0,
  "time_entries": [
    {
      "hours": 1
    },
    {
      "hours": 2
    }
  ]
}}]

This is what I expect :

{"sum_hours" : 3}

So do you know how I can do this ?

1 Answers1

0

Spec

[
  {
    "operation": "shift",
    "spec": {
      "0": {
        "times-entries": {
          "time_entries": {
            "*": {
              // match down to hours, write the value to the 
              //  output as an array
              "hours": "hoursAccumulator[]"
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "sum_hours": "=intSum(@(1,hoursAccumulator))"
    }
  }
]
Milo S
  • 4,466
  • 1
  • 19
  • 22