Skip to main content
Version: 1.0.0

Sorting

sort orders the final array of objects. It always comes at the end of a query.

One field​

Sort in ascending order:

select {name, email} from 'customers.json' sort name

Add ! before a field for descending order:

select {name, email} from 'customers.json' sort !name

Square brackets are optional for one field:

select {name} from 'customers.json' sort [name]

Multiple fields​

Put multiple fields in square brackets:

select {name, surname, id} from 'customers.json' sort [name, !surname, id]

JQL sorts by name first. Rows with the same name are sorted by surname in descending order, then by id in ascending order.

Output fields​

tip

sort reads fields from the result, including renamed and nested fields.

select {customer: {name: profile.name}, total: amount} from 'orders.json'
sort [!total, customer.name]

Nested paths and array indexes are supported:

select {id, items} from 'orders.json' sort items[0].price

Value order​

  • Booleans come before numbers, and numbers come before strings.
  • false comes before true.
  • Numbers use numeric order.
  • Strings use case-sensitive lexical order.
  • ! reverses the order only for the field it marks.
  • Missing and null values stay at the end.
  • Rows with equal sort values keep their original order.

Fields that do not appear in the result are skipped when another requested field is available.