json-path/JsonPath · error · InvalidPathException
Function with name: does not exist.
Error message
Function with name: does not exist.
What it means
PathFunctionFactory.newFunction(name) looks up a registered function class by name (e.g. length(), sum(), concat()). If the name is not in the FUNCTIONS map, it throws InvalidPathException('Function with name: X does not exist.'). This guards the function-call syntax in paths like $.books.length().
Source
Thrown at json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunctionFactory.java:79
/**
* Returns the function by name or throws InvalidPathException if function not found.
*
* @see #FUNCTIONS
* @see PathFunction
*
* @param name
* The name of the function
*
* @return
* The implementation of a function
*
* @throws InvalidPathException
*/
public static PathFunction newFunction(String name) throws InvalidPathException {
Class functionClazz = FUNCTIONS.get(name);
if(functionClazz == null){
throw new InvalidPathException("Function with name: " + name + " does not exist.");
} else {
try {
return (PathFunction)functionClazz.newInstance();
} catch (Exception e) {
throw new InvalidPathException("Function of name: " + name + " cannot be created", e);
}
}
}
}
View on GitHub (pinned to 62a4c9f0f6)
Solutions
- Use a supported built-in function name: length(), sum(), avg(), min(), max(), stddev(), concat(...), append(...).
- For a custom function, register it first: PathFunctionFactory.registerFunction("myfunc", MyFunc.class).
- Print the path and check the segment after '.' before '()' for typos.
- Catch InvalidPathException and validate user-supplied paths against a whitelist of allowed functions.
Example fix
// before Integer n = JsonPath.read(json, "$.books.size()"); // no such function // after Integer n = JsonPath.read(json, "$.books.length()");
Defensive patterns
Strategy: validation
Validate before calling
Set<String> allowed = Set.of("length","sum","avg","min","max","stddev","concat","append");
for (String f : extractFunctionNames(path)) if (!allowed.contains(f)) throw new InvalidPathException("Unknown function: " + f); Try / catch
try {
return JsonPath.read(json, path);
} catch (InvalidPathException e) {
if (e.getMessage().contains("does not exist")) { /* unknown function: report name */ }
throw e;
} Prevention
- Whitelist allowed functions in user-facing path inputs
- Remember the names: length/sum/avg/min/max/stddev/concat/append — not size/count
- Register custom functions with PathFunctionFactory.registerFunction before use
When it happens
Trigger: A path uses function-call syntax with an unknown or misspelled function name — e.g. $.items.size() or $.arr.count() — passed to JsonPath.read()/compile(). Also occurs when a custom function is not registered via PathFunctionFactory.registerFunction().
Common situations: Confusing Java-ish names (size, count) with JsonPath functions (length, sum, avg, min, max, stddev, concat, append), using functions from non-default modules that were never registered, or typos in dynamic path strings.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Arguments to function: '' are not closed properly.
- 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 ']'.
AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11).
Data as JSON: /api/errors/fbac2e39606b17a7.
Report an issue: GitHub.