Ctrl + K
JSON11 min read

JSONPath Guide

Understand JSONPath syntax, operators, filters, array selection and practical techniques for querying and extracting values from JSON documents.

Published: 2026-09-02

JSONPath is a query syntax used to navigate and extract data from JSON documents. It provides a compact way to select properties, array elements, nested objects and groups of values without manually traversing an entire JSON structure in application code.

JSONPath is especially useful when working with API responses, configuration files, logs, automation workflows and large JSON documents. Instead of writing custom traversal logic for every structure, a JSONPath expression can describe exactly which part of the document should be selected.

What Is JSONPath?

JSONPath is a path-based query notation for accessing values inside JSON data. It is conceptually similar to XPath for XML or CSS selectors for HTML, although JSONPath implementations can differ in their supported syntax and features.

A JSONPath expression starts from a JSON document and describes how to navigate through its objects and arrays. Simple expressions can select one property, while more advanced expressions can search nested structures or filter arrays based on conditions.

{
  "user": {
    "name": "Alice",
    "email": "alice@example.com"
  }
}
$.user.name

The expression above selects the name property from the user object and returns the value Alice.

The Root Symbol

The dollar sign ($) represents the root of the JSON document in commonly used JSONPath syntax. Starting an expression with $ makes it clear that navigation begins at the top-level JSON value.

$

A root expression refers to the complete JSON document. From there, additional path components can be used to navigate into properties and arrays.

Selecting Object Properties

The dot notation is one of the simplest ways to access an object property. Place a period after the current path and append the property name.

$.user.name
$.user.email

These expressions navigate from the root to user and then select either name or email. Dot notation is convenient when property names are simple identifiers.

Bracket Notation

Bracket notation provides another way to select object properties. It is particularly useful when a property name contains characters that are inconvenient for dot notation or when you want a more explicit path expression.

$['user']['name']
$['user']['email']

Bracket notation can also make expressions easier to construct dynamically because property names are explicitly represented as strings.

Accessing Nested Objects

JSON objects can contain other objects at multiple levels. JSONPath follows each property in sequence to reach a deeply nested value.

{
  "account": {
    "profile": {
      "contact": {
        "email": "alice@example.com"
      }
    }
  }
}
$.account.profile.contact.email

Each property in the expression represents another level of the JSON hierarchy. This makes JSONPath particularly convenient for extracting values from deeply nested API responses.

Selecting Array Elements

JSON arrays contain ordered elements, and JSONPath can select individual elements by their index. Array indexes are commonly zero-based, meaning the first element has index 0.

{
  "users": [
    {"name": "Alice"},
    {"name": "Bob"},
    {"name": "Charlie"}
  ]
}
$.users[0].name
$.users[1].name
$.users[2].name

The first expression selects Alice, the second selects Bob and the third selects Charlie. Array indexing is useful when the position of the desired element is known.

Selecting All Array Elements

A wildcard can be used to select multiple values instead of a single array element. In commonly used JSONPath syntax, the asterisk (*) represents any matching child.

$.users[*].name

This expression selects the name property from every object in the users array. Wildcards are useful when the same field needs to be extracted from every record.

The Wildcard Operator

The wildcard operator can match any property or array element at a particular level. For example, $.user.* can select all immediate properties of the user object in implementations that support this form.

$.*
$.user.*
$.users[*]

The exact result structure returned by a wildcard depends on the JSONPath implementation and the input document. When building production integrations, verify the syntax and result behavior supported by the specific library or tool being used.

Recursive Descent

The recursive descent operator is commonly written as two periods (..). It searches through nested levels for a property without requiring the complete path to be known in advance.

$..email

An expression such as $..email can find email properties at different levels of the document. This is useful when the same field may appear inside different nested objects.

⚠️ Recursive searches can return more values than expected when a property appears in several parts of a document. Use an explicit path when you need a specific location rather than every matching property.

Array Slices

Some JSONPath implementations support array slicing, allowing a range of elements to be selected instead of one specific index. Slice syntax commonly resembles array slicing in programming languages.

$.users[0:2]

In implementations that support this notation, the expression selects a portion of the users array. Slice behavior can vary between JSONPath implementations, so expressions using advanced features should be tested against the target parser.

Filtering Arrays

One of the most useful JSONPath capabilities is filtering. A filter expression can select array elements whose properties satisfy a condition.

{
  "products": [
    {"name": "Keyboard", "price": 80},
    {"name": "Mouse", "price": 25},
    {"name": "Monitor", "price": 240}
  ]
}
$.products[?(@.price > 50)].name

In implementations supporting this filter syntax, @ refers to the current array element. The expression keeps products whose price is greater than 50 and then selects their name property.

The Current Element Symbol

The at sign (@) is commonly used inside filter expressions to represent the current value being evaluated. This allows conditions to inspect properties of each array element.

$.products[?(@.price >= 100)]

The filter checks the price property of each product. Only elements meeting the condition are selected.

Filtering by String Values

Filters can also compare string properties when the JSONPath implementation supports comparison expressions. This is useful for selecting records based on categories, statuses or other textual fields.

{
  "orders": [
    {"id": 101, "status": "pending"},
    {"id": 102, "status": "completed"},
    {"id": 103, "status": "pending"}
  ]
}
$.orders[?(@.status == 'pending')].id

The expression selects the IDs of orders whose status is pending. Filter syntax is one of the areas where compatibility between JSONPath implementations should be checked carefully.

JSONPath Operators at a Glance

OperatorPurpose
$Root of the JSON document
.Child property
..Recursive descent
*Wildcard
[n]Array element by index
[*]All array elements
[?()] Filter expression in many implementations
@ Current element in filter expressions

Practical JSONPath Examples

Consider a JSON document containing users, their profiles and a list of roles. Different JSONPath expressions can extract specific fields without requiring custom traversal code.

{
  "users": [
    {
      "id": 1,
      "name": "Alice",
      "profile": {
        "country": "US"
      },
      "roles": ["admin", "editor"]
    },
    {
      "id": 2,
      "name": "Bob",
      "profile": {
        "country": "DE"
      },
      "roles": ["viewer"]
    }
  ]
}
GoalJSONPath
All user names$.users[*].name
First user$.users[0]
First user's country$.users[0].profile.country
All countries$.users[*].profile.country
All roles$.users[*].roles[*]
All IDs$.users[*].id

JSONPath for API Responses

API responses often contain multiple levels of metadata and nested arrays. JSONPath can simplify extraction when an application needs only a small portion of a larger response.

$.data.users[*].email

Instead of manually navigating data, users and email properties in application code, a JSONPath expression can describe the required path directly. This can be particularly useful in automation tools that allow users to define extraction rules without writing full programs.

JSONPath for Configuration Files

Configuration files can also be queried with JSONPath. For example, an automation script might need to retrieve a service URL, a deployment environment or a list of enabled features from a larger configuration document.

$.services.api.url
$.environment.name
$.features[*].name

JSONPath vs Manual Traversal

Manual traversal gives developers complete control over how JSON is processed, but it can require more code when structures become deeply nested. JSONPath provides a concise query language that can make extraction rules easier to express and reuse.

ApproachStrength
JSONPathCompact data selection
Manual traversalMaximum programming control
JSONPathUseful for configurable extraction
Manual traversalConvenient for complex application logic

JSONPath Implementations Differ

One important detail about JSONPath is that not every library implements exactly the same language. Basic operations such as root selection, property access and array indexing are widely supported, while filters, slices, expressions and functions can differ considerably.

For this reason, an expression that works in one JSONPath tester or library may behave differently in another. Advanced expressions should always be tested against the implementation used by the application.

💡 Use simple JSONPath expressions whenever possible. They are generally easier to understand, more portable and less dependent on implementation-specific features.

Common JSONPath Mistakes

JSONPath expressions can fail because of incorrect property names, array indexes, unsupported operators or assumptions about the structure of the JSON document. Testing expressions against representative input makes these problems much easier to identify.

  • Using the wrong property name.
  • Forgetting that array indexes are usually zero-based.
  • Using a filter syntax unsupported by the target implementation.
  • Confusing JSONPath syntax with JavaScript property access.
  • Using recursive descent when an explicit path would be safer.
  • Assuming every JSONPath implementation supports the same advanced features.

Best Practices

  • Start with the simplest possible path.
  • Verify the JSON structure before writing the expression.
  • Use explicit property paths when the structure is known.
  • Use wildcards when multiple sibling values are required.
  • Use filters when selection depends on record values.
  • Test advanced syntax against the exact JSONPath implementation being used.
💡 When debugging a complex JSONPath expression, build it step by step. First select the parent object, then the array, then the individual property or filter.

Frequently Asked Questions

What is JSONPath used for?

JSONPath is used to navigate JSON documents and extract specific properties, array elements, nested values or groups of records without manually traversing the entire structure.

What does $ mean in JSONPath?

The dollar sign represents the root of the JSON document in commonly used JSONPath syntax. Paths such as $.user.name start navigation from the top-level value.

How do I select all items in a JSON array?

A commonly used expression is [*]. For example, $.users[*].name selects the name property from every object in the users array.

What does .. mean in JSONPath?

The .. operator is commonly used for recursive descent. It searches through nested levels for a matching property, such as $..email.

Are all JSONPath implementations the same?

No. Basic path operations are widely supported, but filters, slices, expressions and other advanced features can vary between JSONPath libraries and tools.

Helpful JSON Tools

A JSONPath Tester lets you test JSONPath expressions against JSON documents, a JSON Tree Viewer makes nested JSON structures easier to inspect before creating paths, a JSON Field Extractor helps retrieve selected fields from JSON data, a JSON Formatter makes JSON easier to read while debugging expressions, and a JSON Validator checks whether the source JSON is syntactically valid before you test a path against it.

Conclusion

JSONPath provides a concise way to navigate and extract information from JSON documents. Simple expressions can select properties and array elements, while wildcards, recursive descent and filters allow more advanced queries. Because JSONPath implementations can differ in their support for advanced features, expressions should be tested against the specific library or tool used by an application. For API responses, configuration files, automation workflows and structured data processing, JSONPath can significantly simplify repetitive JSON extraction tasks.

Found an issue?

Found an error, outdated information, or something missing from this article? Let me know through the Contact page.

Your feedback helps improve our articles and keep them accurate and useful.