aggregate
Iterates over an array of objects and collects values from specified fields into named lists. For each FieldMapping, every item in the input array is visited and the value at field.label is appended to the output list named field.to. Missing keys produce null entries so that output lists are always the same length as the input array.
Parameters
| Param | Type | Required | Description |
|---|---|---|---|
items | object[] | Yes | Array of objects to aggregate from. Minimum 1 item |
fields | FieldMapping[] | Yes | At least one field mapping. Minimum 1 entry |
fields[].label | string | Yes | The field to extract from each item |
fields[].to | string | Yes | The key name in the output object for the collected values |
Output
A dynamic object where each key is the value of a fields[].to entry, and each value is a list containing one element per input item.
{
"<fields[0].to>": ["value from item 0", "value from item 1", ...],
"<fields[1].to>": ["value from item 0", "value from item 1", ...]
}
Example
Collecting title and author from a list of documents:
{
"id": "aggregateFields",
"type": "aggregate",
"data": {
"label": "Aggregate Fields",
"isExecuted": false,
"handles": ["inputs", "outputs"],
"schema": {},
"params": {
"items": { "value": "{{ @fetchEntries.results }}", "isExpression": true, "isAttachedToInputNode": false },
"fields": {
"value": [
{ "label": "title", "to": "titles" },
{ "label": "author", "to": "authors" }
],
"isExpression": false,
"isAttachedToInputNode": false
}
},
"inputs": [], "outputs": [], "errors": []
},
"position": { "x": 300, "y": 0 },
"isSelected": false,
"isDragging": false
}
Given input items [{ "title": "Deep Learning", "author": "Goodfellow" }, ...], the output will be:
{
"titles": ["Deep Learning", ...],
"authors": ["Goodfellow", ...]
}