arraystring
Use the arraystring() function to convert an array into a single string by joining its elements with a specified delimiter.
Syntax
arraystring (<array>, <delimiter>)Parameters
array
array
Yes
The array field whose elements you want to concatenate into a single string.
delimiter
string
Yes
A string literal that will be used to join the elements of the array.
Returns
The arraystring() function returns a single string where each element of the original array is separated by the specified delimiter.
Usage notes
The function requires an existing XQL-native array field as input.
The function operates on XQL arrays and implicitly converts elements to strings for concatenation.
The specified delimiter is inserted between each element of the original array in the resulting string.
If the input array is empty (for example,
[]), the function returns an empty string ("").This function is typically used within the
alterstage to create new fields or modify existing ones, but can also be used infilterstages.
Examples
Example 1: Converting a string array to a string with a comma and space delimiter
Goal: Convert an array of strings into a single string, separating each element with a comma and a space.
XQL code:
Explanation: The string_tags field contains arrays of strings. The arraystring() function converts each array into a single string, using ", " as the separator between elements.
Output:
101
["security", "login"]
"security, login"
102
["filesystem", "critical"]
"filesystem, critical"
103
["network", "cloud"]
"network, cloud"
Example 2: Converting a numeric array to a string with a pipe delimiter
Goal: Join elements of a numeric array into a single string separated by a pipe character.
XQL code:
Explanation: The numeric_codes field contains arrays of integers. First, arraymap() iterates through each number and converts it to a string using to_string(), creating a new array numeric_codes_as_strings. Then, arraystring() concatenates the elements of this string array using the specified " | " delimiter.
Output:
101
[13, -47, 29, 82, -15]
["13", "-47", "29", "82", "-15"]
13
102
[-21, 56, 13, -88, 42]
["-21", "56", "13", "-88", "42"]
-21
103
[90, -33, 7, 51, -62, 18]
["90", "-33", "7", "51", "-62", "18"]
90
Example 3: Handling an empty array input
Goal: Demonstrate the behavior of the function when the input array is empty.
XQL code:
Explanation: When arraystring() is applied to an empty array ([]), it returns an empty string (""), as there are no elements to join.
Output:
104
[]
""
Example 4: Converting a dynamically sliced array to a string
Goal: Apply the function to a portion of a numeric array created using arrayrange.
XQL code:
Explanation: First, arrayrange(numeric_codes, 0, 2) extracts the first two elements of numeric_codes. Then, arraymap() converts these numeric elements to strings. Finally, arraystring() concatenates these string elements using ", " as the delimiter.
Output:
101
[13, -47, 29, 82, -15]
[13, -47]
["13", "-47"]
"13, -47"
102
[-21, 56, 13, -88, 42]
[-21, 56]
["-21", "56"]
"-21, 56"
103
[90, -33, 7, 51, -62, 18]
[90, -33]
["90", "-33"]
"90, -33"
Example 5: Using arraystring() in a filter stage
Goal: Filter records by creating a string from an array and checking for a specific substring.
XQL code:
Explanation: The combined_tags_for_filter field is created by joining string_tags elements with a hyphen. The filter stage then checks if this new string field contains the substring "security". Only Event IDs containing "security" in their tags are returned.
Output:
101
["security", "login"]
"security-login"
106
["security", "attack"]
"security-attack"
Example 6: Converting application transitions to a delimited string and deduplicating
Goal: Retrieve non-null application ID transitions, convert the transition arrays into strings delimited by " : ", and remove duplicate transition strings based on the insertion time.
XQL code:
Explanation: The query first filters the sample_xql_raw dataset to include only records where action_app_id_transitions contains data. The query renames the field to aait for brevity. The arraystring() function then takes each array of transitions and joins the elements into a single string using " : " as the separator. Finally, the dedup stage ensures that only unique transition strings are retained, ordered by the timestamp.
Output:
["App_1", "App_2", "App_3"]
"App_1 : App_2 : App_3"
["App_A", "App_B"]
"App_A : App_B"
["App_1", "App_5"]
"App_1 : App_5"
Related articles
Functions:
arraymap,arrayrange,to_string
Last updated
Was this helpful?
