{"record":{"id":"686389d1feec40fb","repo":"prestodb/presto","slug":"invalid-function-argument-686389","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Invalid JSON value: %s","messagePattern":"Invalid JSON value: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JsonFunctions.java","lineNumber":107,"sourceCode":"        return JsonPath.build(padSpaces(pattern, charLength.intValue()).toStringUtf8());\n    }\n\n    @ScalarFunction(\"is_json_scalar\")\n    @LiteralParameters(\"x\")\n    @SqlType(StandardTypes.BOOLEAN)\n    public static boolean varcharIsJsonScalar(@SqlType(\"varchar(x)\") Slice json)\n    {\n        return isJsonScalar(json);\n    }\n\n    @ScalarFunction\n    @SqlType(StandardTypes.BOOLEAN)\n    public static boolean isJsonScalar(@SqlType(StandardTypes.JSON) Slice json)\n    {\n        try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {\n            JsonToken nextToken = parser.nextToken();\n            if (nextToken == null) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Invalid JSON value: \" + truncateIfNecessaryForErrorMessage(json));\n            }\n\n            if (nextToken == START_ARRAY || nextToken == START_OBJECT) {\n                parser.skipChildren();\n                if (parser.nextToken() != null) {\n                    // extra trailing token after json array/object\n                    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Invalid JSON value: \" + truncateIfNecessaryForErrorMessage(json));\n                }\n                return false;\n            }\n\n            if (parser.nextToken() != null) {\n                // extra trailing token after json scalar\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Invalid JSON value: \" + truncateIfNecessaryForErrorMessage(json));\n            }\n            return true;\n        }\n        catch (IOException e) {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JsonFunctions.java#L89-L125","documentation":"is_json_scalar throws this when the JSON parser yields no token at all, i.e. the input is empty or not parseable as any JSON value. It is a validity check: the function only answers true/false for well-formed JSON, and anything unparseable raises INVALID_FUNCTION_ARGUMENT with the (truncated) input echoed back.","triggerScenarios":"varchar passed to is_json_scalar that is empty, whitespace-only, or syntactically invalid JSON so nextToken() returns null or the IOException catch path fires.","commonSituations":"Empty-string columns fed from upstream pipelines; columns containing quoted-but-invalid fragments; missing data encoded as '' instead of NULL.","solutions":["Filter out empty/blank strings before calling is_json_scalar.","Fix the producing pipeline to emit valid JSON or NULL.","Wrap the check with try() in Presto to return NULL for invalid input: try(is_json_scalar(x))."],"exampleFix":"-- before\nSELECT is_json_scalar(status) FROM t; -- status can be ''\n-- after\nSELECT if(length(trim(status)) > 0, is_json_scalar(status), false) FROM t;","handlingStrategy":"validation","validationCode":"SELECT is_json_scalar(x) FROM t WHERE length(trim(x)) > 0;","typeGuard":null,"tryCatchPattern":"try { is_json_scalar(x) } catch (PrestoException e) { return false; } // or SQL: try(is_json_scalar(x))","preventionTips":["Replace empty strings with NULL upstream.","Filter blank inputs before JSON functions.","Use try() for defensive ad-hoc analysis."],"tags":["presto","json","invalid-argument"],"backgroundTag":"invalid-json-input","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"}