Array Operation

Contains logic to manipulate arrays

Usage

The Array Operation Node allows you to manipulate arrays in Sanbox. The following are array operations available.

The Array Operation Node is forgiving on input. If you input an object instead of an array, its placed in a new array. If you input nothing, an array is created.

Operation Name

Description

All

Returns true if all elements in an array satisfy a condition.

Any

Returns true if any elements in an array satisfy a condition. If no condition is provided, returns true if there are any elements.

Append

Appends an object to the end of an array.

Concat

Concatenates input array and specified array, producing one array containing items from both.

Filter

Filters an array against a specified condition.

First

Returns the first element in an array that satisfies a condition or null. If no condition is supplied, the first element is returned.

Join

Returns a string containing each item in an array separated by a specified separator.

Last

Returns the last element in an array that satisfies a condition or null.

Get Length

Returns the length of an array.

Reverse

Returns an array containing items with order inverted.

JSONPath

Runs a JSONPath expression against an array and returns the result as an array of objects.

Skip

Bypasses a specified number of elements in an array and then returns the remaining elements.

Sort (Descending)

Sorts an array. Can be sorted generically or by a specified JSONPath.

Sort (Ascending)

Sorts an array. Can be sorted generically or by a specified JSONPath.

Take

Returns a specified number of contiguous elements from the start of an array.

Example - First Product

Consider the following Workflow:

We have an API Request Node configured for endpoint product/{name}. Our Request Node's output is configured to set the productName variable with the name endpoint parameter. We wish to retrieve the product with the specified name. For this example, we have a Gather Node to output the following data.

[
{
"name": "Apple",
"description": "Great fruit.",
"price": 0.5
},
{
"name": "Avacado",
"description": "Full of good fats.",
"price": 1.5
},
{
"name": "Peach",
"description": "Fuzzy?",
"price": 1
},
{
"name": "Grapefruit",
"description": "Once upon a time there was a great Grapefruit named Kyle.",
"price": 1
}
]

Our Array Operation Node receives this data, and is configured to grab the first record with the specified product name.

Array Operation Node Configuration

Testing out our new API in Postman yields the following result:

We can improve our API by providing a Condition Node to check if our First operation returned nothing, and have our API return a 404 Not Found status if so.