Torq’s array utilities let you directly manipulate arrays (adding, filtering, sorting, or restructuring data) within your workflows.
Each section below includes a short description, usage example, and input/output preview.
Category | Description |
Creating and modifying arrays | Add, remove, or update array elements |
Restructuring arrays | Slice, chunk, or reorder arrays for advanced manipulation |
Analyzing and transforming arrays | Extract, filter, or summarize array data |
Creating and modifying arrays
Append to Array
Adds an object to the end of an existing array (or creates a new array if none exists).
Input
["joe", "jane", "jill"]
New_Member
"bob"
Output
["joe", "jane", "jill", "bob"]
Prepend to Array
Adds an object to the beginning of an existing array (or creates one if missing).
Input
["joe", "jane", "jill"]
New_Member
"bob"
Output
["bob", "joe", "jane", "jill"]
Replace in Array
Replaces the first occurrence of a matching object.
Input
["joe", "jane", "jill", "jane"]
Object to Replace
"jane"
New Member
"bob"
Output
["joe", "bob", "jill", "jane"]
Delete from Array
Removes the first matching object from an array.
Input
["joe", "jane", "jill", "jane"]
Object to Delete
"jane"
Output
["joe", "jill"]
Restructuring arrays
Chunk Array
Divides an array into smaller arrays of a specified size. If the array’s length isn’t evenly divisible by the chunk size, the last chunk will contain the remaining elements.
Input
["joe", "jane", "jill", "bob", "doug", "mary"
Chunk_Size
3
Output
[["joe", "jane", "jill"], ["bob", "doug", "mary"]]
Concat Arrays
Merges two arrays, preserving duplicates.
Input
["joe", "jane", "jill"]
Second_Array
["bob", "doug", "mary", "jill", "joe"]
Output
["joe", "jane", "jill","bob", "doug","mary", "jill", "joe"]
Tip: Merging multiple arrays using data transformation
When you need to combine more than two arrays, using multiple Concat Arrays steps can quickly become repetitive and cluttered. Instead, the Data Transformation operator offers a cleaner, faster way to merge multiple arrays in one step, no loops or chained operators required.
Slice Array
Returns a portion of the array starting from the element after Slice_Start and ending with the element at Slice_End (inclusive).
Input
[1, 2, 3, 4, 5]
Slice_Start
2
Slice_End
4
Output
[3, 4]
Slice Array from Start
Extracts elements from the beginning of the array up to (and including) the specified index.
Input
[1, 2, 3, 4, 5]
Slice_End
4
Output
[1, 2, 3, 4]
Slice Array to End
Returns a portion of the array starting from the specified index through the last element.
Input
[1, 2, 3, 4, 5]
Slice_Start
2
Output
[3, 4, 5]
Reverse Array
Reverses the order of elements.
Input
["joe", "jane", "jill", "bob"]
Output
["bob", "jill", "jane", "joe"]
Sort Array
Sorts array items (supports strings, numbers, and datetimes).
Input
["joe", "jane", "jill","bob", "doug","mary" ]
Sort_Order
Ascending
Output
["bob", "doug", "jane", "jill", "joe", "mary"]
Analyzing and transforming arrays
Extract Field from Records
Retrieves the value of the specified field from every record in the provided list.
Input (JSON)
[ { "name": "John Doe", "details": { "age": 23 } },
{ "name": "Jane Doe", "details": {"age": 46 } } ]
Field_Path
details.age
Output
[23, 46]
Tip: Extracting specific values from all objects in an array
When extracting specific values across multiple objects in a JSON array without adding extra steps or transformations, you can use context path notation in Torq to target keys directly inside arrays.
By using * where an array index is expected, you can extract a specific key’s value from all objects within an array. For example:
{{ $.step_name.array.*.name }}This expression returns an array of all name values from every object in the array.
Example 1: Extracting top-level values
Input JSON
{
"array": [
{ "name": "John Doe", "details": { "age": 23 } },
{ "name": "Jane Doe", "details": { "age": 97 } }
]
}Context path
{{ $.step_name.array.*.name }}Output
[
"John Doe",
"Jane Doe"
]
This lets you reference or reuse the result inline, avoiding additional data transformation steps.
Example 2: Extracting nested keys
If you replace * with .., the expression will find all occurrences of the key, even if nested within other objects.
Input JSON
{
"array": [
{
"details": {
"age": 97,
"country": { "name": "UK" }
},
"name": "Jane Doe"
},
{
"details": {
"age": 33,
"country": { "name": "US" }
},
"name": "J Doe"
}
]
}Context path
{{ $.step_name.array..name }}Output
[
"UK",
"Jane Doe",
"US",
"J Doe"
]
Pattern | Description |
| Extracts the value of the specified key from each object in the array |
| Extracts all occurrences of the key, including nested ones |
Filter Array
Filters an array to create a subset of data based on the defined Filter_Func operator and filter criteria. The Field_Path specifies which key or nested value to inspect inside each array item when filtering results.
Input
["joe", "jane", "jill","bob", "doug","mary", "jill", "joe"]
Filter_Func
"Contains"
Field_Path
""
Filter_Arg
j
Output
["joe", "jane", "jill", "jill", "joe"]
Get Array Length
Returns the number of items in an array.
Input
["joe", "jane", "jill"]
Output
3
Get Last Item from Array
Returns the final element.
Input
["joe", "jane", "jill","bob", "doug","mary" ]
Output
"mary"
Rollup Numeric Array
Performs mathematical rollups (Sum, Average, Product, etc.).
Input
[1, 2, 3, 4, 5]
Rollup_Function
Product
Output
120
Subtract Arrays
Compares two arrays and outputs:
intersection (shared items)
left_dif (unique to first)
right_dif (unique to second)
Left_Array
["joe", "jane", "jill","bob", "doug","mary", 1, 2, 3 ]
Right_Array
["joe", "jane", "jill","bob", "doug","mary"]
Output
{
"intersection": ["bob", "doug", "jane", "jill", "joe", "mary"],
"left_dif": [1, 2, 3],
"right_dif": []
}Unique on Array
Removes duplicates from an array.
Input
["joe", "jane", "jill", "bob", "doug","mary", "jill", "joe"]
Output
["joe", "jane", "jill", "bob", "doug", "mary"]
Join Strings
Combines array items into a single string using a delimiter.
Input
["joe", "jane", "jill","bob", "doug","mary" ]
Delimiter
||
Output
"joe||jane||jill||bob||doug||mary"
Use case: Subtract Arrays
This workflow demonstrates how to use the Subtract Arrays utility to detect changes between two datasets, in this case, the current and previous lists of CISA vulnerabilities. By comparing these arrays, the workflow identifies new CVEs and sends a real-time update to a designated Slack channel. For a detailed implementation, refer to the full workflow template.
Retrieve the Latest CVE List: Fetch the current Known Exploited Vulnerabilities (KEV) list from the official CISA API,
{{ $.list_cisa_of_known_exploited_cve_as_json.api_object.vulnerabilities }}Pull the Last Stored CISA Data: Retrieve the most recent dataset used during the previous polling interval from a global variable or data store.
{{ $.stored_cisa_disclosure_data.api_object.value.api_object.vulnerabilities }}If the Lists Differ, Compare the Current and Stored Lists: Use the Subtract Arrays utility to identify new vulnerabilities that have been added since the last check.
Left Array (current):
{{ $.list_cisa_of_known_exploited_cve_as_json.api_object.vulnerabilities }}Right Array (previous):
{{ $.stored_cisa_disclosure_data.api_object.value.api_object.vulnerabilities }}
Step output:
{{ $.compare_previous_results.intersection }}: CVEs already familiar (appear in both lists).{{ $.compare_previous_results.left_diff }}: CVEs not familiar (new vulnerabilities discovered).{{ $.compare_previous_results.right_diff }}: CVEs removed from the source.This value remains empty because the workflow only updates the stored list with the new CISA data.
Continue with the Next Steps: After identifying new CVEs with Subtract Arrays, the workflow loops through
left_diffto enrich each CVE (e.g., via NVD), sends a concise Slack alert, and then updates the stored CISA dataset for the next polling cycle.
Use case: Filter Array
Automate Okta user onboarding by dynamically identifying department approvers and groups using the Filter Array utility. This workflow ensures each new user is routed to the correct approvers and assigned to the proper Okta groups through Slack-based approvals. For a detailed implementation, refer to the full workflow template.
Okta: Retrieve the new user’s full profile from Okta. For example:
Name:
{{ $.event.target.0.displayName }}Department:
{{ $.get_user_by_id.api_object.profile.department }}Manager:
{{ $.get_user_by_id.api_object.profile.manager }}
Define Department Group Approvers Map: Define a JSON map of departments, associated approvers, and group assignments. This structure acts as a dynamic lookup table for access provisioning.
Get Groups and Approvers for Relevant Department: Use the Filter Array utility to match the user’s department to the correct entry in the department map.
Input Array:
{{ $.department_group_approvers_map.data.departments }}Filter Function:
EqualsFilter Argument:
["{{ $.get_user_by_id.api_object.profile.department }}"]Field Path:
name
Step output:
This isolates the correct configuration for the user’s department, providing a clean object that contains both the approver list and group names.
Continue with the Next Steps: After retrieving the department configuration with Filter Array, the workflow loops through approvers to send Slack approval requests, handles approval or denial responses, and, if approved, adds the user to the appropriate Okta groups automatically.



