json-path/JsonPath · error · InvalidPathException
String literal does not have matching quotes. Expected
Error message
String literal does not have matching quotes. Expected
What it means
Raised in FilterCompiler.readStringLiteral when a quoted literal in a filter expression is opened but the matching closing quote is never found (or is escaped), so the scanner consumes to the end of the path. It signals malformed filter syntax, not a data problem; the at-fault input is a path like $.items[?(@.name == 'abc] with an unterminated string.
Source
Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterCompiler.java:316
int endFlagsIndex = endOfFlags(closingIndex + 1);
if (endFlagsIndex > closingIndex) {
CharSequence flags = filter.subSequence(closingIndex + 1, endFlagsIndex);
closingIndex += flags.length();
}
}
filter.setPosition(closingIndex + 1);
}
CharSequence pattern = filter.subSequence(begin, filter.position());
logger.trace("PatternNode from {} to {} -> [{}]", begin, filter.position(), pattern);
return ValueNode.createPatternNode(pattern);
}
private StringNode readStringLiteral(char endChar) {
int begin = filter.position();
int closingSingleQuoteIndex = filter.nextIndexOfUnescaped(endChar);
if (closingSingleQuoteIndex == -1) {
throw new InvalidPathException("String literal does not have matching quotes. Expected " + endChar + " in " + filter);
} else {
filter.setPosition(closingSingleQuoteIndex + 1);
}
CharSequence stringLiteral = filter.subSequence(begin, filter.position());
logger.trace("StringLiteral from {} to {} -> [{}]", begin, filter.position(), stringLiteral);
return ValueNode.createStringNode(stringLiteral, true);
}
private NumberNode readNumberLiteral() {
int begin = filter.position();
while (filter.inBounds() && filter.isNumberCharacter(filter.position())) {
filter.incrementPosition(1);
}
CharSequence numberLiteral = filter.subSequence(begin, filter.position());
logger.trace("NumberLiteral from {} to {} -> [{}]", begin, filter.position(), numberLiteral);
return ValueNode.createNumberNode(numberLiteral);
}View on GitHub (pinned to 62a4c9f0f6)
Solutions
- Add the missing closing quote so the literal is balanced, e.g. $.items[?(@.name == 'abc')]
- If the string itself contains quotes, use the other quote character or the language's escaping convention supported by the parser
- Check for accidental stray quotes earlier in the filter that flipped open/close state
- Sanitize/validate user-supplied filter expressions before handing them to JsonPath.compile or JsonPath.parse
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterCompiler.java:316 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11).
Data as JSON: /api/errors/3c6ec058c0073716.
Report an issue: GitHub.