You write a path that looks right, run it, and get nothing back. No error, no partial result, just an empty answer. JSONPath paths fail quietly like this for a small set of repeatable reasons, each with a different fix, so the first job is naming yours.
This guide walks through the causes: a key name that does not match at that level, an index past the end of the array, a level skipped on the way down, and unsupported syntax. Every example uses the free JSONPath Tester on Ovatly and one small store document.
Contents
- Quick answer
- Mistake 1: the key name does not match at that level
- Mistake 2: an index past the end of the array
- Mistake 3: a missing level on the way down
- Mistake 4: unsupported syntax is a different failure
- The mindset fix: zero matches is a valid result
- How to debug a path, step by step
- Worked example: fixing a broken path against the store data
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Most paths that return nothing mismatch the data in one of three ways: a wrong key name at that level, an index past the end of the array, or a skipped level. Unsupported syntax such as a filter behaves differently: it stops with a clear error naming the part. In the JSONPath Tester, debug by cutting the path back to $ and adding one step at a time until the result turns empty.
Mistake 1: the key name does not match at that level
If the data at a level does not hold the key a step asks for, that step selects nothing, and every step after it has nothing to work on: the whole path returns empty.
The mismatch is often small. The data holds title and the path asks for .name. Or the key exists, just not here: title is a real key in the store data, but it lives inside each book, so $.store.title returns nothing even though the word appears all over the document.
The defence is to read the data at the level you are standing on before writing the next step, rather than writing the whole path from memory.
Mistake 2: an index past the end of the array
Indexes count from zero, so the end of an array arrives one step earlier than most people expect. An array of two books has exactly two valid indexes, [0] and [1]; ask for [2], let alone [5], and the path selects nothing. That is a valid empty result.
This one bites when data shrinks: a path written when the array held ten items keeps working until the day it holds two, and the hardcoded [5] quietly returns nothing.
If the position does not actually matter, the wildcard [*] removes the whole class of mistake by selecting every item whatever the count. If it does matter, check the array length first.
Mistake 3: a missing level on the way down
JSONPath steps are literal: each must exist in the data at the point the path has reached, and a path cannot jump a level because the destination is "obviously" in there somewhere.
The store document nests its books: the root holds store, and store holds book. So $.book[*].title returns nothing, because there is no book key at the root. The path is not wrong about the document's contents, it is wrong about its shape.
When you do not know at which depth a key sits, recursive descent is the supported way to say so: ..title finds title at any depth. Spelling out the levels is better for a kept path: it documents the shape it depends on and breaks loudly when that shape changes.
Mistake 4: unsupported syntax is a different failure
The tester supports a defined subset of JSONPath: $, .key steps, [index], the [*] wildcard over arrays and objects, bracket keys such as ['key'], and ..key recursive descent. Filters such as [?(...)], slices such as [0:2], scripts and unions are not in it.
An unsupported step does not return empty: it stops the test with a clear error naming the part. The two outcomes are opposite diagnoses. An error means the path never ran, so the fix is rewriting that step with a supported one; an empty result means the path ran and found nothing, so the fix is in the earlier steps.
The mindset fix: zero matches is a valid result
One assumption is worth dropping: that an empty result means something broke. It does not. Zero matches is a valid result, the correct answer to the path as written. That reframe turns debugging from "why did it fail" into "at which step did path and data stop agreeing": every step either keeps matching or turns the result empty, and that step is findable in a minute by testing the path in pieces.
How to debug a path, step by step
- Open the JSONPath Tester and paste the JSON. Start the path as just
$and run it. - Add one step, such as
.store, and run again. Note what comes back before moving on. - Keep adding one step at a time, running after each addition, until a step turns the result empty.
- Compare that step against the data at that level: the exact key name, the array length if it is an index, and whether a level sits in between.
- If the tester instead reports an error naming an unsupported part, rewrite that step with a supported one.
Worked example: fixing a broken path against the store data
Here is the store document:
{
"store": {
"book": [
{ "title": "Dune", "author": "Frank Herbert" },
{ "title": "Emma", "author": "Jane Austen" }
]
}
}
The broken path is $.book[*].title: it looks reasonable and returns nothing. Debugging by the steps above, $ returns the whole document. $.book returns nothing, so the break is at the first step: the root's only key is store, and the level was skipped. Rebuilding with it in place, $.store.book[*].title returns:
Dune, Emma
A second path fails differently: $.store.book[5].title also returns nothing, but every level is right. The array holds two books, so [5] is past the end. Same empty answer, different mistake, different fix.
Limitations and honest tradeoffs
The tester evaluates the subset described above, so some valid JSONPath written for other tools will stop here with an unsupported error rather than run: a path that works in a full JSONPath library may not be testable here unchanged.
An empty result also cannot tell you why the data is the way it is: it cannot distinguish a key renamed in a new API version from a field that was always optional. The tester reports what a path selects; interpreting that answer stays with you.
Common mistakes
- Rewriting the whole path at once. Change one step, run, and the guilty step identifies itself.
- Assuming empty means the tool is broken. It ran your path correctly; empty is an answer about the path and the data.
- Treating an unsupported-syntax error as an empty result. The error means the path never ran; empty means it ran and found nothing.
- Guessing key names from a similar response. Read the keys in the document in front of you instead.
- Reaching for a filter first. Filters are unsupported here; most filter questions are really wildcard questions.
FAQs
Is zero matches an error in JSONPath? No. Zero matches is a valid result: the expression ran and selected nothing in the data you gave it. Treat it as information, and debug by rebuilding the path one step at a time.
Why does my filter expression fail instead of returning results? Filters such as [?(...)] are outside the subset this tester supports, and so are slices such as [0:2]. An unsupported part stops the test with a clear error naming it, unlike a supported path returning zero matches.
How do I find where my path breaks? Cut the path back to $ and confirm the document comes back. Add one step at a time, running after each. The step that turns a good result empty is where path and data stop agreeing.
Why does $.book.title return nothing on the store data? Because book is not at the root. The book array sits inside the store object, so the path has to pass through it: $.store.book[*].title. Skipping a level is a common reason paths come back empty.
Is my JSON uploaded to a server when I test a path? No. The JSONPath Tester runs fully in your browser, so the JSON and expressions you test stay on your device.
Conclusion
A path that returns nothing is a clue with a short list of suspects: the wrong key at that level, an index past the end, a skipped level, or a step the tester does not support. Test the path a step at a time in the JSONPath Tester and the guilty step shows itself. Once it matches again, our guide to selecting all items in an array with a JSONPath wildcard covers the [*] step in full, and the rest of the series lives in our Data and JSON Tools guides.
References
- RFC 9535, JSONPath: Query Expressions for JSON, the IETF standard for the syntax used here: https://www.rfc-editor.org/rfc/rfc9535.html
- MDN Web Docs, on working with JSON data in the browser: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON