json-path/JsonPath · error · InvalidPathException
Character '.' on position is not valid.
Error message
Character '.' on position is not valid.
What it means
After consuming a dot token, readDotToken checks whether the current character is another '.': a second consecutive dot where a property is expected (not part of the two-character '..' scan operator) is invalid, so compilation throws InvalidPathException reporting the offending position.
Source
Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java:173
}
return true;
}
}
//
// . and ..
//
private boolean readDotToken(PathTokenAppender appender) {
if (path.currentCharIs(PERIOD) && path.nextCharIs(PERIOD)) {
appender.appendPathToken(PathTokenFactory.crateScanToken());
path.incrementPosition(2);
} else if (!path.hasMoreCharacters()) {
throw new InvalidPathException("Path must not end with a '.");
} else {
path.incrementPosition(1);
}
if(path.currentCharIs(PERIOD)){
throw new InvalidPathException("Character '.' on position " + path.position() + " is not valid.");
}
return readNextToken(appender);
}
//
// fooBar or fooBar()
//
private boolean readPropertyOrFunctionToken(PathTokenAppender appender) {
if (path.currentCharIs(OPEN_SQUARE_BRACKET) || path.currentCharIs(WILDCARD) || path.currentCharIs(PERIOD) || path.currentCharIs(SPACE)) {
return false;
}
int startPosition = path.position();
int readPosition = startPosition;
int endPosition = 0;
boolean isFunction = false;
while (path.inBounds(readPosition)) {View on GitHub (pinned to 62a4c9f0f6)
Solutions
- Fix the extra '.' in the path — use exactly two dots for a scan (`$..price`) and one for property access (`$.price`).
- Sanitize programmatically built paths by collapsing runs of 3+ dots: `path.replace("...", "..")` only if a scan was intended; otherwise remove extras.
- Compile paths in a try-catch during development to catch bad separators early.
Example fix
// before JsonPath.read(json, "$..store...price"); // triple dot // after JsonPath.read(json, "$..store..price"); // or $.store.price
Defensive patterns
Strategy: validation
Validate before calling
String normalizeDots(String p) {
return p == null ? null : p.replaceAll("\\.{3,}", ".."); // keep at most scan '..'
} Try / catch
try {
return JsonPath.read(json, path);
} catch (InvalidPathException e) {
throw new IllegalArgumentException("Invalid dot usage in path: " + path, e);
} Prevention
- Use '..' only for scans and '.' for property access — never three dots.
- Review templated paths that interpolate segments with separators.
- Add a compile-time smoke test for every path constant.
When it happens
Trigger: Paths like `$.a..b` are valid (scan), but `$.a...b`, `$..b.` followed by another dot, or `$.a..` (dot after scan at end via different branch) produce a lone '.' in property position.
Common situations: Typos with too many dots; template string concatenation adding an extra separator before a dynamic segment; confusion between scan `..` and deep-property attempts.
Related errors
- Path must start with '$' or '@'
- Path must not end with a '.
- Failed to parse ArrayIndexOperation:
- Failed to parse token in ArrayIndexOperation:
- Use bracket notion ['my prop'] if your property contains bla
AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11).
Data as JSON: /api/errors/bc6f5577cfca932b.
Report an issue: GitHub.