Hey n8n Community,
Describe the problem/error/question
I am looking for a solution to sum values from the Expression field of my Edit Field node.
Here’s my input:
[
{
"OrderId": "1234",
"OrderDetails": {
"OrderDetails": [
{
"ProductId": "4540",
"Quantity": "1"
},
{
"ProductId": "4601",
"Quantity": "1"
},
{
"ProductId": "7144",
"Quantity": "1"
}
]
}
},
{
"OrderId": "5678",
"OrderDetails": {
"OrderDetails": [
{
"ProductId": "4321",
"Quantity": "1"
}
]
}
}
]
I would like to sum the quantities for each item. From my input, the first item would have a result of 3 (1 + 1 + 1), and the second a result of 1. I have tried to fiddle with JMESPath or reduce, but with no luck.
Would someone have a neat one-liner or solution I could use directly from Edit Fields?
What is the error message (if any)?
None.
Please share your workflow
Share the output returned by the last node
Expected output:
[
{
"orderTotalItems": 3
},
{
"orderTotalItems": 1
}
]
Information on your n8n setup
- n8n version: 1.49.0
- Database (default: SQLite): Default
- n8n EXECUTIONS_PROCESS setting (default: own, main): Default
- Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
- Operating system: Linux