I have a dataweave input as given below.
%dw 2.0
output application/json
var demo = [
{
"mat" : 1000,
"seg" : "z"
},
{
"mat" : 2000,
"seg" : "b"
},
{
"mat" : 3000,
"seg" : "x"
}
]
var count = 0
---
count
I need the sum of the "mat" field, the count should 6000. How do I achieve this ?
I did it like this
%dw 2.0
output application/json
var demo = [
{
"mat" : 1000,
"seg" : "z"
},
{
"mat" : 2000,
"seg" : "b"
},
{
"mat" : 3000,
"seg" : "x"
}
]
var count = sum(demo.mat)
---
count