Skip to main content
Object Utilities

Explore the object utility steps in Torq.

Updated over a week ago

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

Add to object

Create a new object by adding a JSON key, value to an existing object.

Input

{"key": "value", "nested": {"n_key": "n_value"}}
key
{"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 with a different JSON object.

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

Extracts all elements in given paths and constructs a new sparse object from them.

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

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

Run JQ Command

You can slice, filter, map, and transform JSON objects using JQ.

Input

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

JSON Query

[.[] | .name]

Did this answer your question?