---
title: Sort
description: Order the incoming items by one or more fields, or shuffle them randomly
---

Put your items in order by one or more fields, such as cheapest first or newest first, or shuffle them.

## What it does

Sort reorders the whole incoming list at once. No items are added or removed.

* **By fields**: you add sort keys under **Sort By**. Each key names a field, a **Direction** and a way to compare (**Compare As**). Keys apply in order: the second key only decides between items that tie on the first.
* **Random (shuffle)**: the items are put in a random order and the sort keys are ignored.

Items that tie keep their original order. Items where the field is missing, `null` or empty always go **last**, in both directions, so empty rows never float to the top of a descending list.

## When to use it

* Show results newest first or cheapest first before you send or save them.
* Get a real "top 5" by sorting before [Limit](/nodes/builtin/datatransformation/limit/).
* Pick which copy [Remove Duplicates](/nodes/builtin/datatransformation/removeduplicates/) keeps: it keeps the first one, so sort first.
* Take a random sample: shuffle, then Limit.

## Inputs and settings

**Compare As** decides how two values are compared:

* **Automatic** treats values as numbers when it can, then as dates, otherwise as text in natural order.
* **Text (natural)** reads digits as numbers inside text, so `item 2` comes before `item 10`.
* **Text** compares character by character, so `item 10` comes before `item 2`. Use it for codes that must sort strictly by character.
* **Number** and **Date** force that reading. Use **Number** when prices or counts arrive as text.

Use dots for nested fields, for example `price.amount`. A key with an empty **Field** is ignored.

## Outputs

The same items in their new order.

## Dependencies and credentials

None. This node needs no connection and has no slots for other nodes.

## Example workflow

1. [HTML Extract](/nodes/builtin/datatransformation/html-extract/) reads a list of products with `name` and `price` from a shop page.
2. Sort with two keys: **Field** `price`, **Direction** *Ascending*, **Compare As** *Number*; then **Field** `name`, **Direction** *Ascending*, to break ties.
3. [Limit](/nodes/builtin/datatransformation/limit/) with **Max Items** `5` keeps the five cheapest.
4. A [Slack](/nodes/builtin/integration/slack/) node posts them.

## Common issues

* **The order does not change.** Sort needs a list. If the previous node sends one item that holds a list in a field, split it first with [Split Out](/nodes/builtin/datatransformation/splitout/). Also check that at least one key has a **Field**.
* **`10` comes before `2`.** The values are compared as text. Set **Compare As** to *Number*, or *Text (natural)* for text with numbers inside.
* **Empty items sit at the bottom of a descending sort.** This is on purpose: missing and empty values always go last.
* **"No source node is connected to this node."** Connect the node that produces the list to Sort's input.

## Related nodes

* [Limit](/nodes/builtin/datatransformation/limit/): keep the first or last few items after sorting.
* [Remove Duplicates](/nodes/builtin/datatransformation/removeduplicates/): drop copies, keeping the first.
* [Split Out](/nodes/builtin/datatransformation/splitout/): turn a list field into items you can sort.