Loading

Back to Home

$jsonArray

$jsonArray marks a key in the current JSON object as an empty array. Use it when you want to start building an array at a key that does not already hold one.

Syntax

$jsonArray[Key;...]

What happens

  1. $jsonParse loads the JSON object.
  2. $jsonArray converts the value at the given key into an empty array [].
  3. You can then use $jsonArrayAppend or other array functions to populate it.

Example 1: Convert a key to an array

$nomention
$disableInnerSpaceRemoval
$jsonParse[{"games":""}]
$jsonArray[games]
$jsonPretty[2]

What happens:

  1. $jsonParse loads an object where games holds an empty string.
  2. $jsonArray[games] converts games into an empty array.
  3. $jsonPretty[2] shows the result.

Output:

{
  "games": []
}

Example 2: Create an array then append to it

$nomention
$jsonParse[{}]
$jsonArray[items]
$jsonArrayAppend[items;sword]
$jsonArrayAppend[items;shield]
$jsonJoinArray[items;, ]

What happens:

  1. $jsonParse creates an empty object.
  2. $jsonArray[items] creates items as an empty array.
  3. Two $jsonArrayAppend calls add values to it.
  4. $jsonJoinArray displays the result.

Output:

sword, shield

Common uses

See also