prestodb/presto · error · PrestoException
INVALID_FUNCTION_ARGUMENT
INVALID_FUNCTION_ARGUMENT
Error message
Invalid JSON value: %s
What it means
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.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JsonFunctions.java:107
return JsonPath.build(padSpaces(pattern, charLength.intValue()).toStringUtf8());
}
@ScalarFunction("is_json_scalar")
@LiteralParameters("x")
@SqlType(StandardTypes.BOOLEAN)
public static boolean varcharIsJsonScalar(@SqlType("varchar(x)") Slice json)
{
return isJsonScalar(json);
}
@ScalarFunction
@SqlType(StandardTypes.BOOLEAN)
public static boolean isJsonScalar(@SqlType(StandardTypes.JSON) Slice json)
{
try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
JsonToken nextToken = parser.nextToken();
if (nextToken == null) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: " + truncateIfNecessaryForErrorMessage(json));
}
if (nextToken == START_ARRAY || nextToken == START_OBJECT) {
parser.skipChildren();
if (parser.nextToken() != null) {
// extra trailing token after json array/object
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: " + truncateIfNecessaryForErrorMessage(json));
}
return false;
}
if (parser.nextToken() != null) {
// extra trailing token after json scalar
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid JSON value: " + truncateIfNecessaryForErrorMessage(json));
}
return true;
}
catch (IOException e) {View on GitHub (pinned to 55bb57d202)
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)).
Example fix
-- before SELECT is_json_scalar(status) FROM t; -- status can be '' -- after SELECT if(length(trim(status)) > 0, is_json_scalar(status), false) FROM t;
Defensive patterns
Strategy: validation
Validate before calling
SELECT is_json_scalar(x) FROM t WHERE length(trim(x)) > 0;
Try / catch
try { is_json_scalar(x) } catch (PrestoException e) { return false; } // or SQL: try(is_json_scalar(x)) Prevention
- Replace empty strings with NULL upstream.
- Filter blank inputs before JSON functions.
- Use try() for defensive ad-hoc analysis.
When it happens
Trigger: 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.
Common situations: Empty-string columns fed from upstream pipelines; columns containing quoted-but-invalid fragments; missing data encoded as '' instead of NULL.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- INVALID_FUNCTION_ARGUMENT
- Timeout is negative
- LANCE_ERROR
- INVALID_CAST_ARGUMENT
- INVALID_FUNCTION_ARGUMENT
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/686389d1feec40fb.
Report an issue: GitHub.