json-path/JsonPath · error · PathNotFoundException

Missing property in path

Error message

Missing property in path 

What it means

PathNotFoundException thrown by PathToken.handleObjectProperty when the token/upstream is indefinite and the path leaf's property is missing: without REQUIRE_PROPERTIES (which would force the throw path here) or SUPPRESS_EXCEPTIONS to skip it, evaluation still fails because properties are required by default and the requested property is absent.

Source

Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/path/PathToken.java:78

                        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) + "]";
                if(idx.equals("[-1]") || ctx.getRoot().getTail().prev().getPathFragment().equals(idx)){
                    ctx.addResult(evalPath, pathRef, propertyVal);
                }
            }
            else {
                next().evaluate(evalPath, pathRef, propertyVal, ctx);
            }
        } else {
            String evalPath = currentPath + "[" + Utils.join(", ", "'", properties) + "]";

            assert isLeaf() : "non-leaf multi props handled elsewhere";

View on GitHub (pinned to 62a4c9f0f6)

Solutions

  1. Use Option.SUPPRESS_EXCEPTIONS so branches without the property are skipped instead of throwing
  2. Use Option.DEFAULT_PATH_LEAF_TO_NULL to receive null for the missing property
  3. Restructure the path or filter to only match objects guaranteed to contain the property
  4. Catch PathNotFoundException and handle missing data explicitly

Example fix

// before
List<String> authors = JsonPath.read(json, "$..book.author");
// after
Configuration cfg = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
List<String> authors = JsonPath.using(cfg).parse(json).read("$..book.author");
Defensive patterns

Strategy: try-catch

Validate before calling

DocumentContext ctx = JsonPath.parse(json);
List<Map<String, Object>> books = ctx.read("$..book");
boolean allHaveAuthor = books.stream().allMatch(b -> b.containsKey("author"));

Try / catch

try {
    return JsonPath.read(json, indefinitePath);
} catch (PathNotFoundException e) {
    return Collections.emptyList(); // some branches lacked the property
}

Prevention

When it happens

Trigger: Evaluating a path with indefinite segments (e.g. $..* or wildcards) ending in a missing property, e.g. JsonPath.read(json, "$..book.author") where some matched objects lack 'author', with default options (REQUIRE_PROPERTIES semantics) and no suppression.

Common situations: Heterogeneous arrays of objects where only some elements contain the leaf key; querying aggregated API data with optional nested objects.

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


AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11). Data as JSON: /api/errors/4484a34678650147. Report an issue: GitHub.