Sort List
Uncontrolled node
Overview
The Sort List node arranges the elements of a list in either ascending or descending order. It can sort simple values (numbers, strings) or, when provided with a property path, can sort objects and dictionaries by a specific nested property.
The node creates a new sorted copy of the input list and does not modify the original data.
Inputs
| Input | Type | Description | Default |
|---|---|---|---|
| List | Data | The list of items to sort. | - |
| Path | Text | Optional. A dot-separated path to a property within objects/dictionaries to sort by (e.g., user.name or metadata.date). Supports Handlebars variable substitution. | - |
Outputs
| Output | Type | Description |
|---|---|---|
| Output | Data | The sorted list. |
Properties
| Property | Type | Description | Default |
|---|---|---|---|
| Order | Enum | The sort direction: ascending (A-Z, 0-9) or descending (Z-A, 9-0). | ascending |
Runtime Behavior and Defaults
- Uncontrolled Execution: This node runs automatically whenever its input data changes. It does not require an event trigger.
- Copy on Sort: The node creates a shallow copy of the input list (
[...list]) before sorting, ensuring the original input list remains unchanged. - Path Resolution: When a path is provided, the node uses
advancedDerefto resolve nested properties within objects. This supports dynamic paths using Handlebars templates (e.g.,{{sortKey}}). - Comparison Logic: Uses standard JavaScript comparison operators (
<,>). For mixed types, JavaScript's default coercion rules apply. - Empty or Invalid Input: If the input is not a valid array or is empty, the node outputs an error object:
{error: 'Input is not a list'}.
Example
Sorting Simple Values
To sort a list of numbers or strings:
- Connect a list of values to the List input (e.g.,
[3, 1, 4, 1, 5]). - Set Order to
ascendingin the properties panel. - The Output will emit
[1, 1, 3, 4, 5].
Sorting Objects by Property
To sort a list of user objects by their age:
Input List:
[
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25},
{"name": "Charlie", "age": 35}
]
Configuration:
- Path:
age - Order:
ascending
Output:
[
{"name": "Bob", "age": 25},
{"name": "Alice", "age": 30},
{"name": "Charlie", "age": 35}
]
Dynamic Sorting with Variables
You can use Handlebars syntax in the Path input to dynamically select which property to sort by:
- Set Path to:
{{sortField}} - Provide a variable
sortFieldwith value"name"to sort by the name property.
This allows the same workflow to sort by different criteria at runtime.