Skip to main content
Hello and welcome — I’m Mumshad Mannambeth. This lesson introduces JSONPath, a concise query language for extracting data from JSON documents. We’ll:
  • Recap YAML vs JSON
  • Learn JSONPath basics (root, dot notation, array indexing, slices)
  • Work with dictionaries, lists, and nested structures
  • Apply filters / criteria to select items
  • Try practice exercises and review the quiz workflow
A presentation slide titled "Objectives" listing topics like YAML, YAML vs JSON, JSON PATH (Dictionaries, Lists, Lists and Dictionaries, Criteria) and Practice Exercises. A small diagram on the right shows a "JSON PATH - Criteria" example.
This lesson is designed for beginners. We’ll move from simple examples to applied filters so you can practice and build confidence. Consider subscribing to the channel to get notified about new lessons.

YAML vs JSON — quick recap

Both YAML and JSON represent structured data and are often interchangeable. Below is a compact comparison to help you choose the format and convert between them. You can convert between YAML and JSON using online converters (e.g. json2yaml.com) or with small scripts in most languages. Example JSON:
Same data in YAML:
For the rest of this lesson we’ll use JSON examples — YAML can usually be converted to JSON if needed.

What is JSONPath?

JSONPath is a query language for JSON documents, analogous to how XPath works for XML or SQL for relational data. A JSONPath expression navigates the structure of a JSON document and returns matching nodes (typically as an array of matches). Use cases:
  • Extract properties from nested structures
  • Select array elements by index, slice, or condition
  • Support test/quiz platforms that validate JSONPath queries

Basic JSONPath concepts

  • $ — the root of the JSON document.
  • Dot notation — access child properties: $.car.color
  • Bracket notation — access arrays and special keys: $['car'], $[0]
  • Array indices — single index ($[0]), multiple indices ($[0,3]), slices ($[0:3])
  • Filters — inside ?() to test elements: $[?(@.price > 1000)]
  • @ — the current element within a filter expression
JSONPath implementations vary slightly. Some engines always return results as arrays; others may return a single value. When practicing, expect results to be shown as an array of matches.

Quick examples

Given this JSON document:
Common queries and expected results:
  • Get car details Query:
    Result:
  • Get the car’s color Query:
    Result:
  • Get the bus price Query:
    Result:
If your document is nested under a parent like vehicles, then use $.vehicles.car.color.

Arrays (lists) and indexing

If the root is an array:
  • $[0] — first element ("car")
  • $[3] — fourth element ("bike")
  • $[0,3] — first and fourth elements (["car","bike"])
  • Slices: $[1:3] — elements at indices 1 and 2

Dictionaries and lists combined

Consider this car object with a wheels array where each element is an object:
  • $.car.wheels — returns the full wheels array (as a match):
  • Second wheel object (index 1) Query:
    Result:
  • Model of the second wheel Query:
    Result:

Filtering with criteria

Filters let you select array elements based on conditions instead of fixed indexes. Filters are written with ?() and refer to the current element with @. Numeric example: Given the array:
  • Select values greater than 40: Query:
    Result:
Comparison operators (commonly supported):
Support for operators like in / nin, regex matching, or certain logical shortcuts varies by JSONPath engine. If in is not supported, combine comparisons with || (logical OR): (@ == 40 || @ == 43).

Filtering objects by property

Using the wheels example, find the model where location equals rear-right: Query:
Result:
This returns the model value(s) for wheel objects matching the filter.

Practice exercises

Try practical quiz exercises to reinforce what you’ve learned. The KodeKloud quiz interface shows:
  • Top-left: question panel
  • Top-right: controls (Run / Show Solution)
  • Lower-left: source data to query
  • Lower-right: expected output
As you type a JSONPath query, the portal applies it to the source data and shows results instantly. When the result matches the expected output, the question is marked complete. Visit the quiz: https://kodekloud.com/p/json-path-quiz
A screenshot of the KodeKloud JSON Path Quiz webpage showing the KodeKloud logo and browser address bar. The main panel displays a blue quiz card titled "1/14 Dictionary" with instructions to develop a JSON path query and a "SHOW SOLUTION" button.
Example workflow (illustrative) Source data:
Expected output:
Solution query:
The portal shows your result next to the expected output so you can iterate quickly. If you get stuck, use “Show Solution” to reveal the correct JSONPath.
  • JSONPath project: https://github.com/json-path/JsonPath
  • KodeKloud JSONPath quiz: https://kodekloud.com/p/json-path-quiz
  • JSON ↔ YAML conversion tools (example): https://json2yaml.com
If you’d like a follow-up lesson with advanced JSONPath patterns, deeper filter syntax, or walkthroughs for specific quiz items, leave feedback and we’ll prepare more content.

Watch Video

Practice Lab