Agent Script Reference: List Variables

A custom variable can be a list of values. A list can hold any supported variable type, such as strings, booleans, numbers, or objects.

When you create a list in the variables block, specify the variable type in brackets. You can leave the list uninitialized, initialize an empty list, or set default values.

To reference an item in a list, use json_path or bracket [] syntax. Lists are zero-indexed, so to get the first item in your list, use [0].

To reference a field in a list of objects, use data.<field_name>. Note that json_path syntax returns the value enclosed in [""] characters, while bracket syntax returns the raw value.

SyntaxExampleExample Return Value
@variables.<variable_name>[<index>].data.<field_name>The name of the fourth account in a list of accounts:
@variables.all_accounts[3].data.Name
Acme Corp
json_path(@variables.<variable_name>, "$[<index>].data.<field_name>")The name of the fourth account in a list of accounts:
json_path(@variables.all_accounts, "$[3].data.Name")
["Acme Corp"]

This example shows how to use bracket syntax to get the third item in a list of strings.

This example shows:

  • How to use json_path syntax to get the value of the Name field from the third account in a list of Account objects.
  • How to use bracket syntax to get the value of the Name field from the fourth account in a list of Account objects.

You can use these operations on your list variables.

OperationSyntax
Get the length of a listlen(@variables.myList)
Return the maximum of a list of numbersmax(@variables.scores)
Return the minimum of a list of numbersmin(@variables.scores)
Serialize a variable to a JSON stringto_json(@variables.myList)
Use JSONPath syntax to reference a specific value in a listjson_path(@variables.myList, "$[*].name")