Skip to main content

sort

sort is a DTL operation that sorts a sequence in place.

Use it to make ordered lists deterministic, either by item value or by a key in mapping items.

YOp

- sort:
path: users
by: name
order: asc

Parameters

ParameterTypeRequiredDescription
pathstringyesPath to the sequence to sort.
bystringnoKey to sort by when the sequence contains mappings. Omit for scalar sequences.
orderstringnoSort direction. Allowed values are asc and desc. Default is asc.

Behavior

  • Requires the target path to exist.
  • Requires the target to be a sequence.
  • If by is provided, every item must be a mapping containing that key.
  • Uses deterministic comparison: type rank is null, boolean, number, string, array, mapping.
  • Strings sort by Unicode codepoint, not locale collation.

Errors

ErrorMeaning
PATH_NOT_FOUNDTarget path does not exist.
NOT_A_SEQUENCETarget is not a sequence.
INVALID_OPby was provided but an item is not a mapping or lacks that key.

Example

yops:
- sort:
path: items

Input:

items:
- cherry
- apple
- banana

Output:

items:
- apple
- banana
- cherry