{"record":{"id":"6b5f34c6e6c902da","repo":"prestodb/presto","slug":"invalid-function-argument-6b5f34","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Invalid JSON path: '%s'","messagePattern":"Invalid JSON path: '(.+?)'","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JsonPath.java","lineNumber":152,"sourceCode":"    {\n        return new JsonPath(JsonExtract.generateExtractor(pattern, new JsonExtract.ScalarValueJsonExtractor()),\n                JsonExtract.generateExtractor(pattern, new JsonExtract.JsonValueJsonExtractor()),\n                JsonExtract.generateExtractor(pattern, new JsonExtract.JsonSizeExtractor()));\n    }\n\n    private static JsonPath buildJayway(String pattern)\n    {\n        try {\n            Configuration jaywayConfig = Configuration.builder().jsonProvider(new JacksonJsonNodeJsonProvider()).build();\n            if (pattern == null || pattern.isEmpty()) {\n                // for some reason, jayway throws IllegalArgumentException for an empty path, but an InvalidPathException for other invalid paths\n                throw new InvalidPathException();\n            }\n            com.jayway.jsonpath.JsonPath jsonPath = com.jayway.jsonpath.JsonPath.compile(pattern);\n            return new JsonPath(getScalarExtractorForJayway(jsonPath, jaywayConfig), getObjectExtractorForJayway(jsonPath, jaywayConfig), getSizeExtractorForJayway(jsonPath, jaywayConfig));\n        }\n        catch (InvalidPathException ex) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format(\"Invalid JSON path: '%s'\", pattern));\n        }\n    }\n\n    public static JsonPath build(String pattern)\n    {\n        try {\n            return buildPresto(pattern);\n        }\n        catch (PrestoException ex) {\n            if (ex.getErrorCode() == INVALID_FUNCTION_ARGUMENT.toErrorCode()) {\n                return buildJayway(pattern);\n            }\n            throw ex;\n        }\n    }\n\n    public JsonPath(JsonExtract.JsonExtractor<Slice> scalar, JsonExtract.JsonExtractor<Slice> object, JsonExtract.JsonExtractor<Long> size)\n    {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JsonPath.java#L134-L170","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Prefix the path with '$' (root) if it is missing: 'user.name' -> '$.user.name'.","Validate the path syntax against Jayway JsonPath grammar — test it in a standalone JsonPath.compile() or online evaluator before embedding in SQL.","Check for unbalanced brackets/quotes and invalid filter expressions in dynamically built paths.","Escape special characters in object keys, e.g. '$[\"weird.key\"]' instead of '$.weird.key'.","If migrating from legacy path syntax, rewrite the path to Jayway syntax per the migration docs."],"exampleFix":"// before\nSELECT json_extract(payload, 'user.name') FROM events;\n\n// after\nSELECT json_extract(payload, '$.user.name') FROM events;","handlingStrategy":"validation","validationCode":"// Java: validate the JSON path before using it in a query\nimport com.jayway.jsonpath.JsonPath;\nimport com.jayway.jsonpath.InvalidPathException;\n\nboolean isValidJsonPath(String pattern) {\n    if (pattern == null || pattern.isBlank()) return false;\n    try {\n        JsonPath.compile(pattern);\n        return true;\n    } catch (InvalidPathException e) {\n        return false;\n    }\n}","typeGuard":null,"tryCatchPattern":"// Wrap calls that take user-supplied paths\ntry {\n    result = jsonExtract(json, userPath);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"INVALID_FUNCTION_ARGUMENT\")) {\n        log.warn(\"Bad JSON path: \" + userPath);\n        // sanitize or reject the path before retrying\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always start JSON paths with '$'.","Unit-test dynamically built path templates before deploying them.","Use bracket notation for keys with dots or special characters.","Precompile/validate paths in application code (JsonPath.compile) before embedding in SQL.","Consult the Jayway JsonPath syntax reference when migrating from legacy path syntax."],"tags":["presto","json","jsonpath","jayway","invalid-function-argument"],"backgroundTag":"invalid-json-path","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}