OnlineTextLab
Esc

JSONPath Tester

Write a JSONPath query, watch the matches update, and see exactly where each one sits.

Show
Try

Matches

Add a JSON document and a path. Every match appears here as you type.

Runs on your device. Your files and text are not uploaded.

About JSON Path Tester

JSONPath is the query language behind Kubernetes kubectl -o jsonpath output, API gateway mappings and many test assertions. Getting one right by trial and error in a deploy or a test run is slow. Here you paste a document, type a path, and the matches change with every keystroke.

It helps most with the awkward cases: a filter that returns nothing, a recursive search that matches more than you meant, or a key with a dash in it. Switch the view to Values and paths and each match also shows its exact location, which you can then use as a precise query.

How it works

Paths follow RFC 9535, the JSONPath standard. The expression is parsed into child, wildcard, recursive descent, index, slice, union and filter selectors, then walked over your document. Filters are read by a small parser here and never passed to eval, so a path cannot run code on the page.

Results are always a list, as the standard defines them. That is why $.store.bicycle shows one object inside square brackets. The shape stays the same whichever path you try, [] clearly means nothing matched, and [null] means a match whose value is null. A field holding an array appears nested, as [["a","b"]], while [*] lists its items.

How to use JSON Path Tester

  1. Paste your document into the JSON document box, or press Upload. Try an example loads a bookstore sample with a query.
  2. Type your query in JSONPath expression, or press one of the suggestions under Try.
  3. Under Show, pick Values for the matches alone or Values and paths to see where each one is.
  4. Press Copy, or Download to save json-path-result.json.

A filter on the bookstore sample

Input
$.store.book[[email protected] < 10].title
Output
[
  {
    "path": "$['store']['book'][0]['title']",
    "value": "Sayings of the Century"
  },
  {
    "path": "$['store']['book'][2]['title']",
    "value": "Moby Dick"
  }
]

This is the Values and paths view. The book in position 1 costs 12.99, so the filter skipped it, and the path shows that clearly.

When it helps

  • Working out a kubectl -o jsonpath expression against a saved manifest before running it
  • Writing an API test assertion that needs one value from a nested response
  • Finding every occurrence of a field in a large document with $..fieldName
  • Checking that a mapping rule picks the right items before it goes into a gateway config

Tips for a better result

  • Use bracket form for keys with dashes or spaces: $['content-type']. Dot form only reads simple names.
  • Negative indexes count from the end, so $.items[-1] is the last item, and $.items[:2] is the first two.
  • Your path and view are saved in the page address, so you can bookmark or send a query. The JSON stays out of it, and whoever opens the link supplies their own.

Good to know

  • Filter functions such as length(), match() and search() are not supported, though the standard defines them. Comparisons with &&, || and ! are.
  • Other engines differ from RFC 9535. Older libraries, and the template syntax in kubectl, write filters and unwrap results their own way, so check the final expression where it will run.
  • It reads strict JSON only. Convert YAML first with YAML to JSON.
  • Documents opened through Upload must be under 5 MB.

Questions people ask

Why do I get an array for a path that points to one value?

The standard defines a query's result as a list of matches. Keeping that shape means [] always means no match, and a single string looks the same as a list of one. Some libraries unwrap single results, so check what yours does.

What is the difference between . and .. in a path?

A single dot reads a direct child. Two dots search every level below, so $..price finds each price in the document, however deep it sits.

How do I write a filter?

Use [? and refer to the current item with @, as in $.book[[email protected] < 10]. To test that a field exists, leave out the comparison: $.book[[email protected]].

Why does my path return nothing?

Check the spelling and case of the keys, and remember that arrays need [*] or an index before you can reach inside them. $.store.book.title finds nothing, while $.store.book[*].title does.

What to use next

Last reviewed . Read our editorial policy.