Articles in this section

sort helper

The sort helper arranges the elements of an array in ascending or descending order. By default, elements are sorted alphabetically. Use the optional number and reverse parameters to sort numerically or reverse the order.

Syntax

{{sort field [number="true"] [reverse="true"]}}

field -- The field or variable containing the array to sort (e.g. record.items). Required.

number -- Sorts numerically instead of alphabetically when set to "true". Optional. Use this when the array contains numeric strings such as "10" and "2" -- without it, "10" sorts before "2" alphabetically.

reverse -- Sorts in descending order when set to "true". Optional. Combine with number="true" for a descending numeric sort.

Examples

Sort strings alphabetically

{{sort record.items}}

Input: record.items is ["candy", "hat", "toy"]
Output: candy,hat,toy

Sort numbers in ascending order

{{sort record.items number="true"}}

Input: record.items is ["2", "1", "4", "5", "3"]
Output: 1,2,3,4,5

Without number="true", numeric strings sort alphabetically: "1","2","3","4","5" happens to be the same here, but "10" would sort before "2".

Sort numbers in descending order

{{sort record.items number="true" reverse="true"}}

Input: record.items is ["2", "1", "4", "5", "3"]
Output: 5,4,3,2,1

Return raw output with triple braces

{{{sort record.items}}}

Returns the sorted result without Celigo's automatic string wrapping or encoding. Use triple braces when downstream systems require the exact raw output.

Usage notes

  • Default sort order is alphabetical (lexicographic) and ascending. Use number="true" for numeric sorting.
  • If your array contains numeric strings, always use number="true" to avoid unexpected alphabetical ordering (e.g. "10" sorting before "2").
  • Use triple braces ({{{ }}}) for raw output and double braces ({{ }}) when Celigo's default formatting is acceptable.
  • sort returns a new array and does not modify the original.