HTTP & JSON
jsonArrayReverse
$jsonArrayReverse[]
Reverses the order of items in a JSON array in-place.
Syntax
$jsonArrayReverse[key]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| key | string | check_circle Required | — | The key identifying the JSON array to reverse. The key must exist and contain an array. |
Return Value
void
Modifies the array in-place by reversing the element order.
$jsonArrayReverse reverses the order of elements in a JSON array. It operates in-place — the original array is modified. This is useful for displaying data in reverse chronological order or changing the sort direction after an ascending sort. Pair with $jsonArraySort for descending sorts.
Examples
Reverse a simple array
$jsonParse[{"items":["a","b","c","d"]}]
$jsonArrayReverse[items]
Reversed: $jsonJoinArray[items;, ]
// Output: d, c, b, a
Reverse chronological order
$jsonParse[{"posts":["post1","post2","post3"]}]
$jsonArrayReverse[posts]
Most recent: $jsonArrayIndex[posts;0]
Reverse then sort
$jsonParse[{"nums":[5,2,8,1]}]
$jsonArraySort[nums;asc]
$jsonArrayReverse[nums]
Descending: $jsonJoinArray[nums;, ]