structSort

Returns a sorted array of the top level keys in a structure.
Sorts using alphabetic or numeric sorting, and can sort based
on the values of any structure element.

structSort(base, sorttype, sortorder, pathtosubelement) → returns Array

structSort Argument Reference

base
Required

sorttype
Required

* numeric
* text: case sensitive Default.
* textnocase Values:
  • numeric
  • text
  • textnocase

sortorder
Required

* asc: ascending (a to z) sort order. Default.
* desc: descending (z to a) sort order

pathtosubelement
Required

String or a variable that contains one

Examples sample code invoking the structSort function


Simple example for structSort function

Uses the structSort() function to get the sorted structure

SomeStruct = {red=93,yellow=90,green=94};
result = structSort(SomeStruct, "numeric", "desc");
writeOutput( lcase(serializeJSON(result)) );

Expected Result: ["green", "red", "yellow"]


Simple example for structSort function with pathtosubelement

Uses the structSort() function to get the sorted structure

somestruct = {};
someStruct.scott = {age=26, department="General"};
someStruct.glan = {age=29, department="computer"};
someStruct.george = {age=31, department="Physical"};
result = structSort(somestruct, "textnocase", "asc", "department");
writeOutput( lcase(serializeJSON(result)) );

Expected Result: ["glan","scott","george"]


Fork me on GitHub