Skip to main content

Iterator: Group By

Bucket the elements of a list. The sub-graph runs once per element and emits two values to the auto-created Iterator::Collect:

  • key (String) — the bucket label.
  • value (any) — the element to put in that bucket. When omitted, the original element is used.

The result is a JSON object whose keys are the distinct bucket labels and whose values are arrays of the matching elements.

Example
Input: [{name: "alice", team: "A"}, {name: "bob", team: "B"}, {name: "carol", team: "A"}]
Body: key = el.team, value = el.name
Output:
{
"A": ["alice", "carol"],
"B": ["bob"]
}

Parameters

This function has no parameters.

Input

ArrayREQUIRED

List to bucket (Array or JSON array).

Value

Optional value injected into every iteration as value on the entry node.

Output

Result

JSON object — one key per distinct bucket label, each holding an array of the matching values.