json-path/JsonPath · error · PathNotFoundException

No results for path:

Error message

No results for path: 

What it means

EvaluationContextImpl.getValue on a definite (single-result) path throws PathNotFoundException when the evaluation produced zero results — the path simply did not match anything in the document. Unlike indefinite paths, there is no list to be empty; a definite miss is fatal unless exceptions are suppressed.

Source

Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/path/EvaluationContextImpl.java:142

        return Collections.unmodifiableCollection(updateOperations);
    }


    @SuppressWarnings("unchecked")
    @Override
    public <T> T getValue() {
        return getValue(true);
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T> T getValue(boolean unwrap) {
        if (path.isDefinite()) {
            if(resultIndex == 0) {
                if (suppressExceptions) {
                    return null;
                }
                throw new PathNotFoundException("No results for path: " + path.toString());
            }
            int len = jsonProvider().length(valueResult);
            Object value = (len > 0) ? jsonProvider().getArrayIndex(valueResult, len-1) : null;
            if (value != null && unwrap){
              value = jsonProvider().unwrap(value);
            }
            return (T) value;
        }
        return (T)valueResult;
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T> T getPath() {
        if(resultIndex == 0) {
            if (suppressExceptions) {
                return null;
            }

View on GitHub (pinned to 62a4c9f0f6)

Solutions

  1. Add Option.SUPPRESS_EXCEPTIONS to the Configuration (or use JsonPath.parse(...).read with a default via `path(json).read` + null check).
  2. Verify the path matches the actual document structure (print the document or use $..key to check existence).
  3. Use JsonPathOptional / try-catch PathNotFoundException and supply a default value.
  4. For possibly-missing keys, make the path indefinite, e.g. `$.user.email` → `$..email` with ALWAYS_RETURN_LIST.

Example fix

// before
String email = JsonPath.read(json, "$.user.email"); // throws when missing
// after
Configuration cfg = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
String email = JsonPath.using(cfg).parse(json).read("$.user.email", String.class);
if (email == null) email = "";
Defensive patterns

Strategy: try-catch

Validate before calling

boolean pathExists(DocumentContext ctx, String path) {
    Configuration cfg = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS, Option.AS_PATH_LIST).build();
    return !JsonPath.using(cfg).parse(ctx.json()).read(path, List.class).isEmpty();
}

Try / catch

try {
    return JsonPath.read(json, "$.user.email");
} catch (PathNotFoundException e) {
    return defaultValue;
}

Prevention

When it happens

Trigger: JsonPath.read(json, "$.user.email") where `email` key is absent; index out of range like `$.items[5]` on a shorter array; a filter that matched nothing on a definite path.

Common situations: Optional fields missing in API responses; case-sensitive key mismatches; documents older than new schema fields; reading config keys that were renamed.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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