HTTP & JSON jsonArrayAppend

$jsonArrayAppend[]

Appends a value to the end of a JSON array stored under the specified key.

Syntax
$jsonArrayAppend[key;value]

Parameters

Parameter Type Required Default Description
key string check_circle Required The key identifying the JSON array to append to. The key must exist and contain an array.
value string check_circle Required The value to append to the array. Added as the last element.

Return Value

void

Modifies the array in-place by adding the value at the end.

$jsonArrayAppend adds a value to the end of an existing JSON array. It is the JSON equivalent of JavaScript’s Array.push(). The key must exist and must contain an array. Use $jsonArrayUnshift to add to the beginning, and $jsonArrayPop to remove from the end.

Examples

Append a single item

$jsonParse[{"items":["apple","banana"]}]
$jsonArrayAppend[items;cherry]
$jsonStringify[]
// items: ["apple","banana","cherry"]

Build an array dynamically

$json[]
$jsonSet[log;[]]
$jsonArrayAppend[log;User joined]
$jsonArrayAppend[log;Message sent]
$jsonArrayAppend[log;User left]
Events: $jsonJoinArray[log;, ]

Append numeric value

$jsonParse[{"scores":[85,90,78]}]
$jsonArrayAppend[scores;92]
Average: build your own or use jsonforeach