n8n LabIntermediate
Filter an Array of Objects in an n8n Expression
An API returns all orders. You only want to report on the paid ones.
Live Execution Simulator
Idle
π₯
Incoming Data
βοΈ
n8n Node
π―
Next Step
> Ready. Type your expression below and click "Check Answer" to run the node.
Incoming Payload / Data:
{
"orders": [
{ "id": 1, "status": "paid" },
{ "id": 2, "status": "pending" },
{ "id": 3, "status": "paid" }
]
}
$json.orders.filter(o =>
)
βοΈ Your expression is executed against test data β any correct solution passes. +20 XP
β Solution & explanation
$json.orders.filter(o => o.status === 'paid')
Output: [{ "id": 1, ... }, { "id": 3, ... }]
filter() keeps every element where the arrow function returns true. Here each order is named o, so the condition is o.status === 'paid'.π‘ Pro tip: Count them directly: $json.orders.filter(o => o.status === 'paid').length.
Also accepted: o.status == 'paid'