Group By

This function takes a list and outputs an object that's grouped by the values in the original list at the specified path.

Returns an object that groups a list of items (for example, objects, strings, numbers) by the specified path's values. Each unique value for the specified path in the input list will have a corresponding key in the object. For each key in the returned object, this function returns a list of items from the input list that have a matching value to the key's specified path.

Examples

A simple example takes the following as inputs:

Copy
list = 
[
{"a": 1},
{"a": 2},
{"a": 3},
{"a": 3},
{"a": 3}
]

path = a

This function takes the input list, groups it by the specified path and outputs the following:

Copy
{
"1": [ {"a": 1} ],
"2": [ {"a": 2} ],
"3":
[
{"a": 3},
{"a": 3},
{"a": 3}
]
}

A slightly more involved example takes the following inputs:

Copy
list = 
[
{
"a": 1
"b": {"c": 2, "d": 3}
},
{ "a": 4,
"b": {"c": 5, "d": 6}
},
{ "a": 7,
"b": {"c": 8, "d": 6}
}
]

path = b.d

For the preceding input, the function outputs an object that's grouped around the values at the path b.d:

Copy
{
"3":
[
{
"a": 1,
"b":
{
"c": 2,
"d": 3
}
}
],
"6":
[
{
"a": 4,
"b":
{
"c": 5,
"d": 6
}
},
{
"a": 7,
"b":
{
"c": 8,
"d": 6
}
}
]
}
}
],
"3":
[
{"a": 3},
{"a": 3},
{"a": 3}
]
}

Input Fields

  • list (List of items (objects, strings, numbers)) - the list of objects that you want to group by the specified path
  • path (String) - the value or element to group the list by

Output Fields

  • output - the output object, where the keys are the unique values at the path from each element in the original list

Related topics

Lists

Functions in Workflows

Workflow elements