{"record":{"id":"d3c837b6ab2defa9","repo":"prestodb/presto","slug":"invalid-cast-argument-d3c837","errorCode":"INVALID_CAST_ARGUMENT","errorMessage":"Expected a json array or object, but got %s","messagePattern":"Expected a json array or object, but got (.+?)","errorType":"error_code","errorClass":"JsonCastException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JsonToRowCast.java","lineNumber":104,"sourceCode":"                ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)),\n                methodHandle);\n    }\n\n    @UsedByGeneratedCode\n    public static Block toRow(\n            RowType rowType,\n            BlockBuilderAppender[] fieldAppenders,\n            SqlFunctionProperties properties,\n            Slice json)\n    {\n        try (JsonParser jsonParser = createJsonParser(JSON_FACTORY, json)) {\n            jsonParser.nextToken();\n            if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {\n                return null;\n            }\n\n            if (jsonParser.getCurrentToken() != START_ARRAY && jsonParser.getCurrentToken() != START_OBJECT) {\n                throw new JsonCastException(format(\"Expected a json array or object, but got %s\", jsonParser.getText()));\n            }\n\n            BlockBuilder rowBlockBuilder = rowType.createBlockBuilder(null, 1);\n            parseJsonToSingleRowBlock(\n                    jsonParser,\n                    (SingleRowBlockWriter) rowBlockBuilder.beginBlockEntry(),\n                    fieldAppenders,\n                    rowType,\n                    properties);\n            rowBlockBuilder.closeEntry();\n\n            if (jsonParser.nextToken() != null) {\n                throw new JsonCastException(format(\"Unexpected trailing token: %s\", jsonParser.getText()));\n            }\n            return rowType.getObject(rowBlockBuilder, 0);\n        }\n        catch (PrestoException | JsonCastException e) {\n            throw new PrestoException(INVALID_CAST_ARGUMENT, format(\"Cannot cast to %s. %s%n%s\", rowType, e.getMessage(), truncateIfNecessaryForErrorMessage(json)), e);","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JsonToRowCast.java#L86-L122","documentation":"Cast error from the JSON-to-row cast: after skipping a leading null, the parser found a top-level JSON token that is neither an array (positional row fields) nor an object (named row fields). The %s names the token actually found; the JSON text being cast is the faulty input.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JsonToRowCast.java:104 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the JSON is an array of field values (e.g. [1,\"a\"]) or an object keyed by field names","Validate JSON shape with json_format/json_typeof before casting","Match the number/order of fields to the target row type"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}