prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Invalid JSON path: '%s'

What it means

This PrestoException (INVALID_FUNCTION_ARGUMENT) is thrown when a JSON path string passed to JSON functions (json_extract, json_extract_scalar, json_size, etc.) cannot be compiled by the Jayway JsonPath library. The pattern fails JsonPath.compile() (or contains a null/unsupported token per the preceding check), so Presto rejects the argument rather than evaluating it. JSON paths must follow the Jayway/JsonPath syntax, e.g. '$.store.book[0].title'.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JsonPath.java:152

    {
        return new JsonPath(JsonExtract.generateExtractor(pattern, new JsonExtract.ScalarValueJsonExtractor()),
                JsonExtract.generateExtractor(pattern, new JsonExtract.JsonValueJsonExtractor()),
                JsonExtract.generateExtractor(pattern, new JsonExtract.JsonSizeExtractor()));
    }

    private static JsonPath buildJayway(String pattern)
    {
        try {
            Configuration jaywayConfig = Configuration.builder().jsonProvider(new JacksonJsonNodeJsonProvider()).build();
            if (pattern == null || pattern.isEmpty()) {
                // for some reason, jayway throws IllegalArgumentException for an empty path, but an InvalidPathException for other invalid paths
                throw new InvalidPathException();
            }
            com.jayway.jsonpath.JsonPath jsonPath = com.jayway.jsonpath.JsonPath.compile(pattern);
            return new JsonPath(getScalarExtractorForJayway(jsonPath, jaywayConfig), getObjectExtractorForJayway(jsonPath, jaywayConfig), getSizeExtractorForJayway(jsonPath, jaywayConfig));
        }
        catch (InvalidPathException ex) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid JSON path: '%s'", pattern));
        }
    }

    public static JsonPath build(String pattern)
    {
        try {
            return buildPresto(pattern);
        }
        catch (PrestoException ex) {
            if (ex.getErrorCode() == INVALID_FUNCTION_ARGUMENT.toErrorCode()) {
                return buildJayway(pattern);
            }
            throw ex;
        }
    }

    public JsonPath(JsonExtract.JsonExtractor<Slice> scalar, JsonExtract.JsonExtractor<Slice> object, JsonExtract.JsonExtractor<Long> size)
    {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Prefix the path with '$' (root) if it is missing: 'user.name' -> '$.user.name'.
  2. Validate the path syntax against Jayway JsonPath grammar — test it in a standalone JsonPath.compile() or online evaluator before embedding in SQL.
  3. Check for unbalanced brackets/quotes and invalid filter expressions in dynamically built paths.
  4. Escape special characters in object keys, e.g. '$["weird.key"]' instead of '$.weird.key'.
  5. If migrating from legacy path syntax, rewrite the path to Jayway syntax per the migration docs.

Example fix

// before
SELECT json_extract(payload, 'user.name') FROM events;

// after
SELECT json_extract(payload, '$.user.name') FROM events;
Defensive patterns

Strategy: validation

Validate before calling

// Java: validate the JSON path before using it in a query
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.InvalidPathException;

boolean isValidJsonPath(String pattern) {
    if (pattern == null || pattern.isBlank()) return false;
    try {
        JsonPath.compile(pattern);
        return true;
    } catch (InvalidPathException e) {
        return false;
    }
}

Try / catch

// Wrap calls that take user-supplied paths
try {
    result = jsonExtract(json, userPath);
} catch (PrestoException e) {
    if (e.getErrorCode().getName().equals("INVALID_FUNCTION_ARGUMENT")) {
        log.warn("Bad JSON path: " + userPath);
        // sanitize or reject the path before retrying
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling json_extract/json_extract_scalar/json_size with a pattern like 'foo.bar' (missing leading $), '$..[' (unbalanced brackets), '$.items[*]x' (trailing garbage), or any other string Jayway's compiler rejects; buildJayway in JsonPath.java catches the compile error and rethrows as this exception.

Common situations: Hand-written paths forgetting the '$' root prefix; paths built by string concatenation producing syntax errors; copying XPath-style paths into JSON functions; upgrading Presto where the newer Jayway version is stricter about syntax than the old built-in parser.

Understand the failure class

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/6b5f34c6e6c902da. Report an issue: GitHub.