Breadcrumbs

JSONPath Basics

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

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


Example JSONPath

JSONPath

Result

$.result[*]

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

$.result[0]

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

$.result[*].name

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

$.result[0].name

JSON
"Wooden Gloves"

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

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

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

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

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

2

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

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

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

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

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