HTTP & JSON
jsonArrayUnshift
$jsonArrayUnshift[]
Adds a value to the beginning of a JSON array, shifting all existing elements up by one index.
Syntax
$jsonArrayUnshift[key;value]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| key | string | check_circle Required | — | The key identifying the JSON array. The key must exist and contain an array. |
| value | string | check_circle Required | — | The value to insert at the beginning of the array. |
Return Value
void
Modifies the array in-place by prepending the value.
$jsonArrayUnshift adds a value to the front of a JSON array — equivalent to JavaScript’s Array.unshift(). Existing elements shift up by one index. This is useful for priority queues, where high-priority items are inserted at the front and processed before normal items via $jsonArrayShift.
Examples
Prepend an item
$jsonParse[{"log":["second","third"]}]
$jsonArrayUnshift[log;first]
$jsonJoinArray[log;, ]
// Output: first, second, third
Build a timeline in reverse
$json[]
$jsonSet[timeline;[]]
$jsonArrayUnshift[timeline;Event C - 3pm]
$jsonArrayUnshift[timeline;Event B - 2pm]
$jsonArrayUnshift[timeline;Event A - 1pm]
$jsonForEach[timeline]
$jsonValue[]
$endJsonForEach
Priority insert
$jsonParse[{"queue":["normal1","normal2"]}]
$jsonArrayUnshift[queue;URGENT]
Next: $jsonArrayShift[queue]