json.path

Using this function you can query an element within JSON data. To reach the desired node or a specific field in the node in the JSON data, you must follow a specific notation defined in the JsonPath specification. See https://jqlang.github.io/jq/manual/ for details on the notation to be used and specific examples of using the notation.

Important: See the section Mapping JSON Data with the json.path() Function for a detailed explanation on using the json.path() function.

Syntax

json.path(path, object)

Arguments

Argument

Type

Description

path

string

The search path to the element within the JSON data.

object

any

The JSON object that contains the JSON data you are searching.

Returns

Type

Description

any

The result of the JSON path.

Examples

Let us say the jsonObject includes the following: 

jsonObject = {
"colors": [
{ "id": 1, "value": "red" },
{ "id": 2, "value": "green" },
{ "id": 3, "value": "blue" }
]
}

The function json.path("$loop.colors[?(@.id == 2)].value[0]", jsonObject) returns green.