A JSONPath bug almost never announces itself. There is no exception and no stack trace. The code runs, the field comes back empty, and the page quietly renders without the data it was supposed to show. When someone finally notices, the debugging question is miserable: is the path wrong, or did the response change shape?

Testing the expression before it ships separates those two suspects. Paste a sample response, run the path, and read what it actually matches. This guide uses the free JSON Path Tester on Ovatly, which runs fully in your browser, and it is honest about the subset of JSONPath the tester speaks, because an expression built on unsupported syntax fails here first.

Contents

  • Quick answer
  • The subset the tester speaks
  • Why test outside your code
  • How to test a JSONPath, step by step
  • Worked example: pulling book titles from a store response
  • When your expression uses a filter
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

To test a JSONPath before using it in your code: paste a real sample response into the JSON Path Tester, type the expression, and check that the matches are exactly the values you expect, no more and no fewer. Stay inside the supported subset ($, dot and bracket keys, [index], [*], ..key); filters, slices, scripts and unions produce a clear error naming the part, so rewrite those paths before they ship. Treat zero matches as a valid result, not a failure: the expression and the sample disagree, which is what the test exists to reveal.

The subset the tester speaks

JSONPath has grown dialects, and not every engine accepts every construct. The tester supports a defined subset, and knowing its borders is most of the skill.

Supported: $, the root of the document. Dot notation, as in $.store.book. Bracket notation, as in $['store']['book'], the form for keys containing spaces, dots or other characters that dot notation would misread. Indexes, as in [0] for the first array item. The wildcard [*], which matches every item at one level and works over both arrays and objects. And recursive descent, ..key, which finds a key at any depth.

Not supported: filters such as [?(@.price > 10)], slices such as [0:2], script expressions, and unions. When an expression uses one of these, the tester does not guess. It stops and names the unsupported part, turning a vague failure into a specific instruction: rewrite this piece.

Why test outside your code

Inside an application, a JSONPath result is buried under everything else the code is doing. An empty result could mean the path is wrong, the response shape changed, the request returned an error body, or the data genuinely has no such field. Four suspects, one silent symptom.

A tester isolates the expression. The data is fixed, because you pasted it, so every result is a verdict on the expression alone. If $.store.book[*].title returns the titles you expect from the sample, the expression is proven against that shape, and a later empty result in production points at the data, not at your path.

The sample you test against is a real response, captured as it actually arrived, with the nesting and key names the API really uses. Expressions written from documentation alone routinely assume a level that is not there, or a key spelled the way the docs wished it was.

How to test a JSONPath, step by step

  1. Capture a real response, exactly as the API returned it, pretty-printed or not.
  2. Open the JSON Path Tester and paste the response in.
  3. Start with a short expression, such as $.store, and confirm it matches what you expect.
  4. Extend the path one step at a time: a key, then an index or wildcard, then the final key. Watch the match count change, so you know which step loses or gains matches.
  5. Compare the matches against the sample by eye. The right expression returns every value you wanted and none you did not.

Worked example: pulling book titles from a store response

Take this sample response, with a store holding an array of two books:

{
  "store": {
    "book": [
      { "title": "Dune", "author": "Frank Herbert" },
      { "title": "Emma", "author": "Jane Austen" }
    ]
  }
}

The goal is every book title. Build the expression in stages. $.store matches the store object. $.store.book matches the array. Adding the wildcard and the final key:

$.store.book[*].title

The tester returns two matches: Dune and Emma. That is the complete expected set, so the expression is proven against this shape. Notice what the wildcard did: it applied the .title step to each item in the array. The bracket form, $['store']['book'][*]['title'], returns the same matches and is the safer habit when key names contain characters that dot notation would trip over. A recursive alternative, $..title, also returns both titles here, and would keep working if the books later moved a level deeper.

When your expression uses a filter

The most common reason an expression fails in the tester is that it was written with a filter, for example a path keeping only books above a price:

$.store.book[?(@.price > 10)].title

Filters are outside the supported subset, and the tester refuses this expression with an error naming the filter. Read that as the test doing its job early: the same construct may or may not survive in the engine your code uses, and here you learn about the dependency before it ships. The rewrite is to split the job in two. Use the wildcard to collect the candidate values, $.store.book[*], then apply the condition to the results, in the tester by eye or in your code where the filtering logic belongs. The path stays portable, and the condition stays visible.

Limitations and honest tradeoffs

The subset is a real limit. If your production engine supports filters and slices and your code depends on them, this tester cannot prove those expressions, and it will tell you so rather than approximate them. Treat that as a boundary, not a defect: expressions inside the subset are proven exactly, expressions outside it are refused honestly.

The test is also only as good as the sample. A path proven against one response can still meet a differently shaped response later, for example an array that arrives as a single object when it holds one item. Testing against two or three samples narrows that risk. The tester checks expressions against data you paste; it does not fetch URLs or call the API, so the freshness of the sample is your responsibility.

Common mistakes

  • Shipping the first expression that returns something. A path can return values and still be wrong, matching a sibling field. Compare the matches against the sample, value by value.
  • Treating zero matches as a crash. Zero matches is a valid result. It means the expression found nothing in this data, which is a finding about the path or the sample, not a tool failure.
  • Writing filters out of habit. Many JSONPath examples online use [?(...)]. Here that syntax is refused by name. Reach for the wildcard first.
  • Testing against documentation examples. Docs show the shape the author intended. Test against a captured response, which shows the shape that actually arrives.

FAQs

Why does the tester reject my JSONPath expression? The tester supports a defined subset of JSONPath: $, dot keys, bracket keys, indexes, the [*] wildcard and .. recursive descent. Filters, slices, scripts and unions are not supported, and when an expression uses one, the error names that part so you know what to rewrite.

Is zero matches an error? No. Zero matches is a valid result. It means the expression ran correctly and found nothing in the data you gave it. Useful information before the expression ships: either the path is wrong, or the sample does not contain the field you expected.

Can I use a filter like [?(@.price > 10)] in the tester? No. Filters are outside the supported subset and the tester will refuse the expression with an error naming the filter. Rewrite the path with a wildcard to collect the values first, then select from the results.

What is the difference between a wildcard and recursive descent? The wildcard [*] matches every item at one level, across arrays and objects. Recursive descent, written ..key, searches for that key at any depth below the current point, so it finds matches whose nesting you do not know in advance.

Is my JSON uploaded to a server when I test an expression? No. The tester runs fully in your browser and the JSON never leaves your device, so you can test against real response samples, including sensitive ones.

Conclusion

A JSONPath expression is a claim about the shape of data. Testing it against a real sample, inside the JSON Path Tester, turns that claim into a checked fact before your code depends on it, and its clear errors and honest zero-match results show exactly where the two part ways. The same inspect-before-you-trust habit applies to plain tabular data, which is why our guide on fixing a CSV file that opens in one column in Excel starts by viewing the file before blaming it. For more guides in this series, see our Data and JSON Tools guides.

References