A JSONPath expression selects specific elements of JSON data.

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