Skip to main content
Hello, and welcome to this lesson.
An orange presentation slide with the title "JSON PATH" and the subtitle "PART - 3 - LISTS." Faint geometric node-and-line graphics appear in the background.
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)
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
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.
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
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):
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
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].
Quick reference table 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 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.

Watch Video

Practice Lab