Skip to content

Sort

The Sort node orders the elements of an array by a given field, in ascending or descending order. It lets you force the comparison type (number or text) or let the node detect it automatically.

It is equivalent to n8n’s Sort node.

If no source is provided, the node operates on the array received in the previous node’s data. When data is not an array but contains an items or data property that is one, the node uses it automatically. If the field is left empty, elements are sorted by their own value (useful for arrays of simple values).

ParameterTypeRequiredDescription
sourcetextNoDot-notation path to the array within data. Empty = uses data directly. Example: items, result.rows
fieldtextNoField to sort by (dot-notation within each item). Empty = sorts by the item value itself
orderselectNoasc (default): ascending. desc: descending
typeselectNoauto (default): detects the type. number: compares as a number. string: compares as text

The node returns the sorted array directly (compatible with other nodes that expect an array):

[
{ "name": "T-shirt", "price": 12 },
{ "name": "Pants", "price": 30 },
{ "name": "Coat", "price": 80 }
]

If the input is not an array (and has no items/data array), the node returns an error asking you to set source or connect a node that returns an array.

{
"label": "Cheapest first",
"field": "price",
"order": "asc",
"type": "number"
}
{
"label": "Alphabetical order",
"field": "name",
"order": "asc",
"type": "string"
}
{
"label": "Highest score",
"source": "result.rows",
"field": "stats.score",
"order": "desc",
"type": "number"
}

Sorts the result.rows array by stats.score from highest to lowest.

  • With type: auto, the comparison respects the native type of the values (numbers, strings, ISO dates as text)
  • The source field supports dynamic and cross-node variables: {{@NodeName.field}}, {{#N.field}}
  • The node does not mutate the input array: it returns a sorted copy
  • Does not require credentials