json-path/JsonPath · error · InvalidPathException
Empty properties
Error message
Empty properties
What it means
PropertyPathToken represents a property access (e.g. $.foo) in a compiled JSON path. The constructor rejects an empty list of properties because a path token must reference at least one property name; an empty token would make the compiled path meaningless. This is thrown at path-compilation time, before any document is evaluated.
Source
Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/path/PropertyPathToken.java:38
import com.jayway.jsonpath.internal.PathRef;
import com.jayway.jsonpath.internal.Utils;
import java.util.ArrayList;
import java.util.List;
import static com.jayway.jsonpath.internal.Utils.onlyOneIsTrueNonThrow;
/**
*
*/
public class PropertyPathToken extends PathToken {
private final List<String> properties;
private final String stringDelimiter;
public PropertyPathToken(List<String> properties, char stringDelimiter) {
if (properties.isEmpty()) {
throw new InvalidPathException("Empty properties");
}
this.properties = properties;
this.stringDelimiter = Character.toString(stringDelimiter);
}
public List<String> getProperties() {
return properties;
}
public boolean singlePropertyCase() {
return properties.size() == 1;
}
public boolean multiPropertyMergeCase() {
return isLeaf() && properties.size() > 1;
}
public boolean multiPropertyIterationCase() {View on GitHub (pinned to 62a4c9f0f6)
Solutions
- Ensure the property list passed to PropertyPathToken (or the path string given to JsonPath.compile) contains at least one non-empty property name
- Trim/validate user-supplied path strings and reject or skip empty segments before compiling
- If generating paths dynamically, guard: if (properties.isEmpty()) throw new IllegalArgumentException(...) or skip token creation
- Use the public JsonPath.compile/PathCompiler APIs instead of instantiating PropertyPathToken directly
Example fix
// before
List<String> props = Arrays.asList(raw.split("\\."));
PropertyPathToken token = new PropertyPathToken(props, '\'');
// after
List<String> props = Arrays.stream(raw.split("\\."))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
if (props.isEmpty()) throw new IllegalArgumentException("path has no properties");
PropertyPathToken token = new PropertyPathToken(props, '\''); Defensive patterns
Strategy: validation
Validate before calling
List<String> props = Arrays.asList(segment.split("\\."));
if (props.stream().anyMatch(String::isEmpty)) throw new IllegalArgumentException("empty property in path"); Type guard
boolean valid = properties != null && !properties.isEmpty();
Prevention
- Never build path tokens from unvalidated user input
- Filter empty segments after splitting path strings
- Prefer public JsonPath.compile over internal token classes
When it happens
Trigger: Calling Filter.path(...) or internal APIs that build a PropertyPathToken with an empty List<String> properties, e.g. new PropertyPathToken(Collections.emptyList(), '\u0000') or mis-using internal path-builder APIs (PathCompiler) with no property segments.
Common situations: Building paths programmatically from user input or config where the property name is an empty string or filtered out; writing custom PathToken/predicate code against jayway internals; splitting a path string on '.' when the string starts or ends with a dot, producing empty segments.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- 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
- Filter must start with '[' and end with ']'.
- Filter must start with '[?' and end with ']'.
AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11).
Data as JSON: /api/errors/32e04c55081be5a7.
Report an issue: GitHub.