Skip to main content

Object Utilities

Explore the object utility steps in Torq.

Updated over 2 weeks ago

Use these utility steps to work with objects. See below for examples of each step's input and output.

Add to object

Add a new key–value pair to an existing JSON object, returning an updated object that includes the additional data.

Input

Input: {"key": "value", "nested": {"n_key": "n_value"}}
Key: key
Parameters: {"new": "json value"}

Output

{
"changed": false,
"length": 2,
"overwritten": false,
"result": {
"key": "value",
"nested": {
"n_key": "n_value"
}
},
"step_status": {
"code": 1,
"message": "",
"verbose": ""
}
}

Extend object

Extends a JSON object by adding a second JSON object, returning an updated object that includes the additional data. Extend object merges an entire JSON object into the input, while Add to object inserts a single key–value pair only.

Input

Input: {"key": "value", "nested": {"n_key": "n_value"}}

Second object: {"key_2": "value_2", "nested": "no"}

Output

{  
"result": {
"key": "value",
"key_2": "value_2",
"nested": {
"n_key": "n_value"
}
}

Extract fields to sparse objects

Extract specific fields from a JSON object to create a smaller, filtered object that contains only the specified data.

Input

[
{
"name": "John Doe",
"details": {
"age": "20",
"citizenships": {
"US": true,
"Germany": false
}
}
},
{
"name": "Peter Schenk",
"details": {
"age": "37",
"citizenships": {
"US": false,
"Germany": true
}
}
}
]


Paths: name,details.age,details.citizenships.Germany

Output

[
{
"details": {
"age": "20",
"citizenships": {
"Germany": false
}
},
"name": "John Doe"
},
{
"details": {
"age": "37",
"citizenships": {
"Germany": true
}
},
"name": "Peter Schenk"
}
]

Run JQ command

Slice, filter, map, and transform JSON objects using JQ. You can generate JQ with AI.

Input

[{"name":"apple","color":"green","price":1.2},{"name":"banana","color":"yellow","price":0.5},{"name":"kiwi","color":"green","price":1.25}]

JSON Query

.[] | select(.color=="green") 

Output

[
{
"color": "green",
"name": "apple",
"price": 1.2
},
{
"color": "green",
"name": "kiwi",
"price": 1.25
}
]

Use case: Run JQ command

A suspicious login triggers an alert. Extract key information, and if the user has an admin role, send a notification to the security team. Include the relevant details in the Slack message notification.

  1. Use the Run JQ command step to extract the relevant information from the alert context. The required data is the user name, user email, IP address, and role. You can use the Generate JQ with AI option to build the JQ command, or enter it manually.

  2. Use the If operator to check if the user has admin permissions. If yes, then send a Slack message to the security team with the most relevant details of the alert.

Did this answer your question?