> ## 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.

# JSON Path Lists

> Explains JSONPath array operations including indexing, multiple indices, slicing, strides, and negative indices with examples and portability tips.

Hello, and welcome to this lesson.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/RMI5Z0UHsJ07Jee-/images/JSON-Path-Test-Free-Course/Lesson/JSON-Path-Lists/json-path-part-3-lists-slide.jpg?fit=max&auto=format&n=RMI5Z0UHsJ07Jee-&q=85&s=b6a6117b45004c0ffaad9c2ed21b9055" alt="An orange presentation slide with the title &#x22;JSON PATH&#x22; and the subtitle &#x22;PART - 3 - LISTS.&#x22; Faint geometric node-and-line graphics appear in the background." width="1920" height="1080" data-path="images/JSON-Path-Test-Free-Course/Lesson/JSON-Path-Lists/json-path-part-3-lists-slide.jpg" />
</Frame>

My name is Mumshad Mannambeth.

This lesson continues our JSONPath series and focuses on querying lists (arrays) with JSONPath. You’ll learn the most useful array operations: direct indexing, selecting multiple indices, slicing (ranges), stepping (stride), and negative indices to access elements from the end.

Example JSON array (top ten brand names)

```json theme={null}
[
  "Apple",
  "Google",
  "Microsoft",
  "Amazon",
  "Facebook",
  "Coca-Cola",
  "Samsung",
  "Disney",
  "Toyota",
  "McDonald's"
]
```

Indexing basics

* Arrays are zero-indexed: the first element is index 0.
* You can select a single element or multiple specific elements by index.

Examples

| JSONPath query | Result |
| - | - |
| `$[0]` | `["Apple"]` |
| `$[3]` | `["Amazon"]` |
| `$[0,3]` | `["Apple", "Amazon"]` |

<Callout icon="lightbulb" color="#1CB2FE">
  Different JSONPath engines vary in how they return single matches. Some return the raw value (e.g., `"Apple"`), while others return a singleton array (e.g., `["Apple"]`). For consistency, the examples in this lesson show array-wrapped outputs. When integrating JSONPath in scripts, check how your library or tool returns matches.
</Callout>

Slicing (ranges)

* Use the slice syntax `$[start:end]` to select a contiguous range of elements.
* This follows the common convention: include `start` and exclude `end` (select indices start through end-1).

Examples

```text theme={null}
$[0:4] -> [
  "Apple",
  "Google",
  "Microsoft",
  "Amazon"
]

$[0:5] -> [
  "Apple",
  "Google",
  "Microsoft",
  "Amazon",
  "Facebook"
]
```

Step (stride)

* Add a third value to the slice to specify a step: `$[start:end:step]`.
* A `step` of `2` selects every second element (skip one element between selections).

Example — select every other item from the first eight elements (indices 0–7):

```text theme={null}
$[0:8:2] -> [
  "Apple",
  "Microsoft",
  "Facebook",
  "Samsung"
]
```

Note: not all JSONPath implementations support the step/stride syntax. If portability is important, verify your engine’s documentation or avoid stride syntax when uncertain.

Negative indices and selecting the last elements

* Some implementations accept negative indices in slices. Negative indices count from the end: `-1` is the last element, `-2` is the second-to-last, etc.
* Using a single negative index like `$[-1]` may or may not be supported across engines.
* A more portable form is a slice-style negative index: `$[-1:]` selects the last element and is accepted by more implementations.
* Similarly, `$[-3:]` returns the last three elements.

Examples

```text theme={null}
# When supported:
$[-1] -> ["McDonald's"]

# Portable slice forms:
$[-1:] -> ["McDonald's"]
$[-3:] -> [
  "Disney",
  "Toyota",
  "McDonald's"
]
```

<Callout icon="warning" color="#FF6B6B">
  JSONPath engines implement features differently. To maximize portability across libraries and tools, prefer slice-style negative indices (e.g., `$[-1:]`, `$[-3:]`) rather than relying on single negative-index syntax like `$[-1]`.
</Callout>

Quick reference table

| Operation | Syntax | Description | Example |
| - | - | - | - |
| Single index | `$[i]` | Select element at index `i` | `$[0]` -> `["Apple"]` |
| Multiple indices | `$[i,j,...]` | Select specific indices | `$[0,3]` -> `["Apple","Amazon"]` |
| Slice (range) | `$[start:end]` | Select indices start..end-1 | `$[0:4]` -> first 4 items |
| Slice with step | `$[start:end:step]` | Range with stride | `$[0:8:2]` -> every 2nd item |
| Negative slice | `$[-n:]` | Last `n` elements | `$[-3:]` -> last 3 items |

Practice tips

* Try these queries against your own JSON or use online testers such as Jayway’s JSONPath evaluator or jsonpath.com to observe how different engines return results.
* When writing scripts, check the library’s API docs for return types and supported syntaxes.

Links and references

* Jayway JSONPath (Java) — [https://github.com/json-path/JsonPath](https://github.com/json-path/JsonPath)
* JSONPath.com — [https://jsonpath.com/](https://jsonpath.com/)
* JSONPath on Wikipedia — [https://en.wikipedia.org/wiki/JSONPath](https://en.wikipedia.org/wiki/JSONPath)

That covers the common list-related operations in JSONPath: direct indexing, selecting multiple indices, slicing, stepping, and negative indices for end-relative access. Try hands-on exercises to reinforce these patterns.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/json-path-test-free-course/module/114e6dee-a9f2-49f3-a0c6-cdfb92f74310/lesson/c94d843c-16dd-45e5-bda6-c318f29d16d5" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/json-path-test-free-course/module/114e6dee-a9f2-49f3-a0c6-cdfb92f74310/lesson/0b357686-dc66-41ba-9c59-845dadec6773" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.