json-path/JsonPath · error · PathNotFoundException
No results for path:
Error message
No results for path:
What it means
PathNotFoundException thrown by PathToken.handleObjectProperty when a property does not resolve during evaluation, neither SUPPRESS_EXCEPTIONS nor REQUIRE_PROPERTIES handling applies to silently skip it, and the token/upstream is considered definite — meaning the path pointed at a value that simply does not exist in the document.
Source
Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/path/PathToken.java:66
String property = properties.get(0);
String evalPath = Utils.concat(currentPath, "['", property, "']");
Object propertyVal = readObjectProperty(property, model, ctx);
if(propertyVal == JsonProvider.UNDEFINED){
// Conditions below heavily depend on current token type (and its logic) and are not "universal",
// so this code is quite dangerous (I'd rather rewrite it & move to PropertyPathToken and implemented
// WildcardPathToken as a dynamic multi prop case of PropertyPathToken).
// Better safe than sorry.
assert this instanceof PropertyPathToken : "only PropertyPathToken is supported";
if(isLeaf()) {
if(ctx.options().contains(Option.DEFAULT_PATH_LEAF_TO_NULL)){
propertyVal = null;
} else {
if(ctx.options().contains(Option.SUPPRESS_EXCEPTIONS) ||
!ctx.options().contains(Option.REQUIRE_PROPERTIES)){
return;
} else {
throw new PathNotFoundException("No results for path: " + evalPath);
}
}
} else {
if (! (isUpstreamDefinite() && isTokenDefinite()) &&
!ctx.options().contains(Option.REQUIRE_PROPERTIES) ||
ctx.options().contains(Option.SUPPRESS_EXCEPTIONS)){
// If there is some indefiniteness in the path and properties are not required - we'll ignore
// absent property. And also in case of exception suppression - so that other path evaluation
// branches could be examined.
return;
} else {
throw new PathNotFoundException("Missing property in path " + evalPath);
}
}
}
PathRef pathRef = ctx.forUpdate() ? PathRef.create(model, property) : PathRef.NO_OP;
if (isLeaf()) {
String idx = "[" + String.valueOf(upstreamArrayIndex) + "]";View on GitHub (pinned to 62a4c9f0f6)
Solutions
- Check the JSON actually contains the property at that path before reading
- Add Option.REQUIRE_PROPERTIES awareness: configure Option.DEFAULT_PATH_LEAF_TO_NULL to get null instead of an exception
- Add Option.SUPPRESS_EXCEPTIONS to return an empty result instead of throwing
- Catch PathNotFoundException and treat it as a missing value in the caller
Example fix
// before
String email = JsonPath.read(json, "$.user.email");
// after
Configuration cfg = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
String email = JsonPath.using(cfg).parse(json).read("$.user.email", String.class); Defensive patterns
Strategy: try-catch
Validate before calling
Object v = null;
try { v = JsonPath.parse(json).read(path); } catch (PathNotFoundException ignored) {}
boolean exists = v != null; Try / catch
try {
String val = JsonPath.read(json, "$.user.email");
} catch (PathNotFoundException e) {
String val = null; // treat as absent field
} Prevention
- Configure Option.SUPPRESS_EXCEPTIONS or Option.DEFAULT_PATH_LEAF_TO_NULL for tolerant reads
- Remember properties are required by default in jayway JsonPath
- Validate document shape against expected schema before querying optional fields
- Centralize reads in a helper that handles PathNotFoundException
When it happens
Trigger: JsonPath.read(json, "$.user.email") where 'email' key is absent from the JSON and no Option.AS_PATH_LIST/DEFAULT_PATH_LEAF_TO_NULL is set; reading a definite path against an incomplete document.
Common situations: API responses missing optional fields, documents from different schema versions, tests expecting a key that the fixture omits.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Missing property in path
- Filter: %s can only be applied to arrays. Current context is
- No results for path:
- The path is null
- Expected to find an object with property %s in path %s but f
AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11).
Data as JSON: /api/errors/bcece28de0eecdbc.
Report an issue: GitHub.