Using arrays, strings, and complex structures with DataPrime
Goal
By the end of this guide you should be able to manipulate arrays, transform and analyze strings, and access deeply nested fields. You’ll learn how to split strings, decode values, flatten complex objects, and troubleshoot keypath issues that can break queries.
Why it matters
Real-world logs rarely come in clean. Arrays often need to be expanded, strings need parsing or decoding, and deeply nested or oddly named fields can get in the way of querying. This guide shows you how to handle that complexity with confidence using DataPrime.
explode
– Split array elements into rows
Description
Use explode
when you need to analyze each element in an array as its own document. This is useful for permissions, tags, error lists, and other multi-valued fields.
Syntax
Example – Flatten scopes
for permission analysis
Input data
Query
Result
{ user_id: 1, scope: read, scopes: [read, write] }
{ user_id: 1, scope: write, scopes: [read, write] }
arrayConcat
– Combine multiple arrays into one
Description
Use arrayConcat
to merge two or more arrays into a single array field. Ideal for combining values split across fields (e.g., job queues, error types).
Syntax
Example – Merge frontend and backend error arrays
Input data
Query
Result
arrayAppend
– Add a value to the end of an array
Description
Use arrayAppend
to add a value to the end of an array field. This is useful when the value is available, but stored separately from the array.
Syntax
Example 1 – Add a static job step
Input data
Query
Result
Example 2 – Append a field value into the array
Input data
Query
Result
arrayContains
– Check if a value exists in an array
Description
Use arrayContains
to determine if a specific value appears inside an array. Returns a boolean.
Syntax
Example – Flag blocked IP addresses
Input data
Query
Result
Parsing and transforming strings
arraySplit
– Split a string into parts
Description
Use arraySplit
to break a string into parts using a delimiter. Often used for names, paths, versions, or tags.
Syntax
Example – Split full name into first and last
Input data
Query
Result
arrayJoin
– Join array values into a string
Description
Use arrayJoin
to convert an array into a readable string using a delimiter.
Syntax
Example – Format a user action log
Input data
Query
Result
urlDecode
/ urlEncode
– Decode or encode URL-safe strings
Description
Use urlDecode
to make encoded strings readable. Use urlEncode
when you need to safely transmit or store text.
Syntax
Example – Decode a query string parameter
Input data
Query
Result
decodeBase64
– Decode base64 strings
Description
Use decodeBase64
to convert encoded strings (e.g., compressed URLs or payloads) into readable values.
Syntax
Example – Decode a base64 URL
Input data
Query
Result
contains
, startsWith
– Check for string patterns
Description
Use contains
or startsWith
to detect substrings in a string field. Useful for filtering by prefix, domain, or label.
Syntax
Example – Identify log types or domains
Input data
Query
Result
choose
– Flatten deeply nested fields
Description
Use choose
to extract a deeply nested field and bring it to the top level. Makes it easier to read and query.
Syntax
Example – Simplify metric access
Input data
Query
Result
extract ... using kv()
– Parse key-value strings
Description
Use extract ... using kv()
to convert a structured string into a map of fields. Add datatypes
to cast values into numbers or timestamps.
Note
There are several extractor functions that can be used with the extract
command.
Syntax
Example – Parse and cast query parameters
Input data
Query
Result
Bracket notation – Access special keypaths
Description
Use bracket notation to access keys that contain dots, spaces, or special characters. Required in archive/compliance mode.
Syntax
Example – Filter by a key with dots
Input data
Query
Result
Common pitfalls or gotchas
- Exploding arrays removes other fields unless you preserve them. Always use
original preserve
unless you want a minimal result. - String length limits can break string functions. If a field is longer than 256 characters, some functions may silently return
null
in high-tier mode. - Always quote bracketed keypaths. Even one missed bracket or dot can break your query.