Loading

Back to Home

$jsonArraySort

$jsonArraySort sorts a JSON array in ascending order. Numbers are sorted from lowest to highest. Strings are sorted by their ASCII/Unicode values, with uppercase letters coming before lowercase.

Syntax

$jsonArraySort[Key;...]

What happens

  1. $jsonParse loads the JSON object.
  2. $jsonArraySort sorts the array at the given key path in ascending order.
  3. Nothing is returned. Use $json or $jsonJoinArray to see the sorted result.

Example 1: Sort a number array

$nomention
$jsonParse[{"scores":[50,10,90,30,70\]}]
$jsonArraySort[scores]
$jsonJoinArray[scores;, ]

What happens:

  1. $jsonParse loads the object.
  2. $jsonArraySort[scores] sorts the numbers ascending.
  3. $jsonJoinArray displays the result.

Output:

10, 30, 50, 70, 90

Example 2: Sort a mixed array

$nomention
$jsonParse[{"data":["banana",10,"apple",2,"Apples",30\]}]
$jsonArraySort[data]
$jsonJoinArray[data;, ]

What happens:

  1. $jsonParse loads the object.
  2. $jsonArraySort[data] sorts it: numbers first, then strings by ASCII value (Apples before apple before banana).
  3. $jsonJoinArray displays the result.

Output:

2, 10, 30, Apples, apple, banana

Common uses

See also