Tool Pocket
Reset
Back

🔍 JSON path

Extract elements from JSON using JSON path.

Understanding JSONPath

JSONPath is a query language for JSON data, similar to how XPath is used for XML. It allows you to extract specific data from a JSON structure using a concise and flexible syntax.

JSONPath Syntax

Here are some essential JSONPath operators:

OperatorDescription
$Root element of the JSON
.Direct child (dot notation)
[i]Array indexing
..Recursive descent (searches all levels)
*Wildcard (matches any property or array element)
?()Filter expression

JSONPath Queries for the Example JSON

Consider the following JSON array:

Accessing the Root ($)

Returns the entire JSON array.

Accessing an Array Element ($.cities[0].name)

Returns the name of the first city in the array.

Accessing All Names ($..name)

Returns all the names in the JSON.

Differece between $..name and $[*].name is that $..name will return all the names in the JSON, including nested objects, while $[*].name will only return the names of the objects in the root array. For instance, using $[*].name on the example JSON will return below:

Filtering by Population ($.cities[?(@.population > 3000000)])

returns the cities with a population greater than 3,000,000.

Usage

  1. Enter the JSON into the input pane.
  2. Enter the JSON path query.
  3. Click the 'Select' button.
  4. The selected elements will be displayed on the output pane.