Back to Home
$jsonArrayAppend
$jsonArrayAppend appends a value to the end of a JSON array
at the specified key.
Syntax
$jsonArrayAppend[Key;...;Value]
-
Key: one or more keys forming the path to the array. -
Value: the value to append. Can be a string, integer, float, or boolean.
What happens
$jsonParseloads the JSON object.-
$jsonArrayAppendadds the value to the end of the array at the given key path. -
Nothing is returned. Use
$jsonor$jsonJoinArrayto see the updated array.
Example 1: Append to a simple array
$nomention
$jsonParse[{"fruits":["apple","banana"\]}]
$jsonArrayAppend[fruits;orange]
$jsonJoinArray[fruits;, ]
What happens:
-
$jsonParseloads the object with a two-itemfruitsarray. -
$jsonArrayAppend[fruits;orange]addsorangeto the end. $jsonJoinArraydisplays the updated array.
Output:
apple, banana, orange
Example 2: Append multiple values
$nomention
$jsonParse[{"fruits":["apple","banana"\]}]
$jsonArrayAppend[fruits;orange]
$jsonArrayAppend[fruits;grape]
$jsonJoinArray[fruits;, ]
What happens:
-
$jsonParseloads the object with a two-itemfruitsarray. -
Two
$jsonArrayAppendcalls addorangethengrapeto the end. $jsonJoinArraydisplays the updated array.
Output:
apple, banana, orange, grape
Common uses
- Building lists: add items to an array one at a time
- Inventory systems: add purchased items to a user's inventory array
- Logging: append entries to a history or log array
See also
- $jsonArrayPop: to remove the last element
- $jsonArrayUnshift: to add a value to the front instead
- $jsonArrayCount: to check how many elements are in the array