In this guide, you’ll learn how to leverage JSONPath expressions to query, filter, and slice JSON arrays effectively. JSONPath is a powerful query language for JSON, enabling developers to pinpoint data within nested structures, perform conditional selections, and iterate through collections.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
1. Defining an Array in JSON
Consider a JSON document representing a set of users:users is an array of objects. Each object has id, name, and age properties.
2. Accessing Array Elements
2.1 By Index
Pick a single element by its zero-based index:2.2 Using Wildcard
Retrieve all users with the wildcard*:
2.3 Slicing the Array
Extract a range of elements with slice notation[start:end]:
start or end:
[:2]→ first two elements[2:]→ from the third element onward
JSONPath uses zero-based indices. Negative indices or step values (e.g.,
[::2]) are not supported in all implementations.3. Filtering Array Elements
Apply a filter expression to select items matching a condition:3.1 Accessing Properties of Filtered Results
Chain selectors to extract specific fields:4. Nested Arrays
Given nested arrays, you can flatten or traverse them:5. Summary of JSONPath List Operators
| Operator | Description | Example |
|---|---|---|
[index] | Selects a single element by position | $.users[0] |
[*] | Wildcard to select all elements | $.users[*] |
[start:end] | Slice array between start (inclusive) and end | $.users[1:3] |
[?()] | Filter by expression | $.users[?(@.age>25)] |
Chaining (.) | Traverse nested arrays or access properties | $.groups[*].members[*] |