AppendItemsArrayJSON

Appends new elements to an array.

AppendItemsArrayJSON(
  array: str, 
  items: str | list[str]
)

Where:

  • array: An array in the format "[]" (an empty array) or '[{"first_name": "Brad", "last_name": "Pitt"}]' for example.
  • items: A string or list of strings in the format ['{"first_name": "Brad", "last_name": "Pitt"}'] for example.

Example

The example below appends two sets of elements to an empty array and displays the result in the Sandbox chat.

{{set(
   name="MyArray",
   value=AppendItemsArrayJSON(
       array="[]",
       items=[
           '{
               "first_name": "Brad",
               "last_name": "Pitt"
           }',
           '{
               "first_name": "Matt",
               "last_name": "Damon"
           }'
       ]
   )
)}}

{{SendMessage(message=MyArray)}}

{{set(
   name="MyArray",
   value=AppendItemsArrayJSON(
       array=MyArray,
       items=[
           '{
               "first_name": "Leonardo",
               "last_name": "DiCaprio"
           }',
           '{
               "first_name": "Robert",
               "last_name": "De Niro"
           }'
       ]
   )
)}}

{{SendMessage(message=MyArray)}}
[{"first_name":"Brad","last_name":"Pitt"},{"first_name":"Matt","last_name":"Damon"}]

[{"first_name":"Brad","last_name":"Pitt"},{"first_name":"Matt","last_name":"Damon"},{"first_name":"Leonardo","last_name":"DiCaprio"},{"first_name":"Robert","last_name":"De Niro"}]