Cortex XSOAR Transform Language (commonly referred to as DT) is used for various functions within Cortex XSOAR related to Context. In it's most basic sense, DT is a query language for JSON objects. If you are familiar with JSONQuery, this should be very familiar to you.
We are going to use the following as our example context and go over the various ways that DT can be used to access, aggregate, and mutate data.
DT can go deep. Deep like cosmic brownies and Jimi Hendrix at 2am deep. But in its essence, we are dealing with a dictionary of key values. Let's look at the following example.
Using the context example noted above, these are the various ways that DT can be used to access nested keys.
Dealing with Arrays
We access array values just as we would any other dictionary (or JSON) key in dot notation, with an index.
Indexes start at 0! The first is not "1", we are dealing with code, not sheep.
Let's take a look at the above context.
Under "URLScan", we have an array called "Certificates". If we wanted to access the "SubjectName" value of the first entry, we would use the following DT statement.
|["www.google.com", "*.google.com", "www.google.de", "*.g.doubleclick.net", "*.apis.google.com"]|
|["www.google.com", "*.google.com", "www.google.de"]|
If you want to retrieve a range of results, you can use
[0:9] where "0" is the beginning of the array and "9" is the 9th position in the array.
You will notice that
The following are a few examples of selector methods:
|will return only Vendors that exactly match the Acrobat description.|
|will return any SubjectName that starts with "www"|
|will return any SubjectName that contains doubleclick.|
|will return any Country that contains IE or ie or any mixed case.|
|will return all ValidTo for certificates that have SubjectName ending with de. Please notice that we tested a relative path to “SubjectName” (“de”) and returned a different path (“ValidTo”).|
|will return all SubjectNames for Certificates that have the same ValidTo time as the first Certificate in the array. Please notice that the bind value (val1) does not start with ‘.’ and will DT the context from the top context.|
Selectors are great for avoiding duplicate entries and can be used to add context to existing entries.
An example of how this may be used in your code is the following:
The code snippet
'URL(val.Data && val.Data == obj.Data)' will look for entries in the context whose name found under "Data" are the same. If it finds a match, it will update the existing context, If it does not, it will create a new entry in the context because it views the entry as "unique" to the existing values.
Here are a few examples:
|Returns the timestamp where the SubjectName contains the word "doubleclick". Then it appends "Z" to the value|
|returns all the organizations but in lower case.|
|returns all the Vendors containing “Recorded” but in lower case.|
|returns the concatenated ip and vendor for all DBotScores.|