---
title: sort
description: "Sort an array by value or object property."
---

# sort

Sort an array by value or object property.

## Syntax

```knap
{{ value | sort }}
{{ value | sort:"desc" }}
{{ value | sort:"name" }}
{{ value | sort:("name", "desc") }}
```

## Usage

- Arrays sort in ascending order by default. Pass `desc` to reverse the direction.
- Pass a property name to sort objects by that property. A dotted path selects a nested property.
- With both a property and direction, wrap the parameters in parentheses.
- Numbers are compared numerically. Missing and `null` property values remain at the end.
- Serialized arrays and objects produced by another filter are recognized automatically.

## Examples

### Numbers

```json title="Data"
{
  "values": [
    10,
    2,
    1
  ]
}
```

```knap title="Template"
{{ values | sort }}
```

```md title="Output"
[1,2,10]
```

### Descending

```json title="Data"
{
  "values": [
    "a",
    "c",
    "b"
  ]
}
```

```knap title="Template"
{{ values | sort:"desc" }}
```

```md title="Output"
["c","b","a"]
```

### Object property

```json title="Data"
{
  "people": [
    {
      "name": "Lin"
    },
    {
      "name": "Ada"
    }
  ]
}
```

```knap title="Template"
{{ people | sort:"name" }}
```

```md title="Output"
[{"name":"Ada"},{"name":"Lin"}]
```

## Related filters

- [reverse](/filters/reverse)
