json-path/JsonPath · error · InvalidPathException
Not enough predicates supplied for filter [] at position
Error message
Not enough predicates supplied for filter [] at position
What it means
InvalidPathException thrown by readPlaceholderToken when a filter path uses positional '?' placeholders (e.g. [?,?]) but fewer predicates were pushed onto filterStack than there are comma-separated placeholder tokens. Each '?' must correspond to a predicate supplied earlier via Filter.predicate(...).
Source
Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java:430
}
char nextSignificantChar = path.nextSignificantChar(questionmarkIndex);
if (nextSignificantChar != CLOSE_SQUARE_BRACKET && nextSignificantChar != COMMA) {
return false;
}
int expressionBeginIndex = path.position() + 1;
int expressionEndIndex = path.nextIndexOf(expressionBeginIndex, CLOSE_SQUARE_BRACKET);
if (expressionEndIndex == -1) {
return false;
}
String expression = path.subSequence(expressionBeginIndex, expressionEndIndex).toString();
String[] tokens = expression.split(",");
if (filterStack.size() < tokens.length) {
throw new InvalidPathException("Not enough predicates supplied for filter [" + expression + "] at position " + path.position());
}
Collection<Predicate> predicates = new ArrayList<Predicate>();
for (String token : tokens) {
token = token != null ? token.trim() : null;
if (!"?".equals(token == null ? "" : token)) {
throw new InvalidPathException("Expected '?' but found " + token);
}
predicates.add(filterStack.pop());
}
appender.appendPathToken(PathTokenFactory.createPredicatePathToken(predicates));
path.setPosition(expressionEndIndex + 1);
return path.currentIsTail() || readNextToken(appender);
}
View on GitHub (pinned to 62a4c9f0f6)
Solutions
- Supply one predicate (Filter.filter(...) or Criteria) per '?' placeholder in the path
- Remove extra '?' tokens from the path that have no matching predicate
- Count '?' occurrences in the path and assert the predicate array length matches before querying
Example fix
// before
JsonPath.query("$..book[?,?]", filterA)
// after
JsonPath.query("$..book[?,?]", filterA, filterB) Defensive patterns
Strategy: validation
Validate before calling
long placeholders = path.chars().filter(c -> c == '?').count();
if (placeholders != predicates.size()) {
throw new IllegalArgumentException("Path has " + placeholders + " placeholders but " + predicates.size() + " predicates supplied");
} Try / catch
try {
return JsonPath.query(path, predicates.toArray());
} catch (InvalidPathException e) {
if (e.getMessage().startsWith("Not enough predicates")) {
throw new IllegalArgumentException("Predicate count mismatch for path: " + path);
}
throw e;
} Prevention
- Generate the '?' placeholders and the predicate list together in one builder method
- Assert placeholder count equals predicate count before calling JsonPath
- When editing queries, update path and predicates in the same change
When it happens
Trigger: Calling JsonPath.query(path, predicate) with fewer predicate arguments than '?' placeholders in the path, e.g. path "$..book[?(@.a)][?,?]" style patterns with only one predicate supplied for two '?' tokens.
Common situations: API migration where predicates were removed from the call but the path string kept multiple placeholders; building paths dynamically and miscounting placeholders.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Expected '?' but found
- Filter: %s can not be applied to primitives. Current context
- Could not find matching close quote for %s when parsing : %s
- Could not find matching close for %s when parsing regex in :
- Expected character: %c
AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11).
Data as JSON: /api/errors/8f630edf273f0689.
Report an issue: GitHub.