JsonPath is a simple and powerful tool for extracting specific data from JSON documents. It is a query language that allows you to navigate through the JSON structure and access the values you need.

JsonPath uses a dot notation syntax, allowing you to specify the path to the desired value.

The most important symbols used in a JSONPath

JSONPath Syntax

Description

$

the root element. A JSONPath mostly starts with this symbol

@

the current element

. or []

child operator

*

wildcard. Targets all elements of a list

?()

defines an element filter

&&

AND operator

||

OR operator

Example JSON

{
  "results": [
    {
      "id": 1,
      "name": "Wooden Gloves"      
    },
    {
      "id": 2,
      "name": "Fresh Wood"
    }
  ]
}
JSON

Example JSONPath

JSONPath

Result

$.result[*]

{
  "id": 1,
  "name": "Wooden Gloves"      
},
{
  "id": 2,
  "name": "Fresh Wood"
}
JSON

$.result[0]

{
  "id": 1,
  "name": "Wooden Gloves"      
}
JSON

$.result[*].name

[
  "Wooden Gloves", 
  "Fresh Wood" 
]
JSON

$.result[0].name

"Wooden Gloves"
JSON

$.result[?(@.id == 1)]

{
  "id": 1,
  "name": "Wooden Gloves"      
}
JSON

$.result[?(@.name == 'Fresh Wood')]

{
  "id": 2,
  "name": "Fresh Wood"
}
JSON

$.result[?(@.name == 'Fresh Wood')].id

2

$.result[?(@.id == 1 || @.i d== 2)]

{
  "id": 1,
  "name": "Wooden Gloves"      
},
{
  "id": 2,
  "name": "Fresh Wood"
}
JSON

$.result[?(@.name == 'Fresh Wood' && @.id == 2)]

{
  "id": 2,
  "name": "Fresh Wood"
}
JSON

A simple JSONPath sandbox to play around with can be found here and the JSONPath expression definition here