{"record":{"id":"bce885e21eb2210c","repo":"apache/flink","slug":"illegal-json-array-data","errorCode":null,"errorMessage":"Illegal JSON array data...","messagePattern":"Illegal JSON array data\\.\\.\\.","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonParserToRowDataConverters.java","lineNumber":354,"sourceCode":"        final int scale = decimalType.getScale();\n        return jp -> {\n            BigDecimal bigDecimal;\n            if (jp.currentToken() == JsonToken.VALUE_STRING) {\n                bigDecimal = new BigDecimal(jp.getText().trim());\n            } else {\n                bigDecimal = jp.getDecimalValue();\n            }\n            return DecimalData.fromBigDecimal(bigDecimal, precision, scale);\n        };\n    }\n\n    private JsonParserToRowDataConverter createArrayConverter(ArrayType arrayType) {\n        JsonParserToRowDataConverter elementConverter = createConverter(arrayType.getElementType());\n        final Class<?> elementClass =\n                LogicalTypeUtils.toInternalConversionClass(arrayType.getElementType());\n        return jp -> {\n            if (jp.currentToken() != JsonToken.START_ARRAY) {\n                throw new IllegalStateException(\"Illegal JSON array data...\");\n            }\n            List<Object> result = new ArrayList<>();\n            while (jp.nextToken() != JsonToken.END_ARRAY) {\n                Object convertField = elementConverter.convert(jp);\n                result.add(convertField);\n            }\n            final Object[] array = (Object[]) Array.newInstance(elementClass, result.size());\n            return new GenericArrayData(result.toArray(array));\n        };\n    }\n\n    private JsonParserToRowDataConverter createMapConverter(\n            String typeSummary, LogicalType keyType, LogicalType valueType) {\n        if (!keyType.is(LogicalTypeFamily.CHARACTER_STRING)) {\n            throw new UnsupportedOperationException(\n                    \"JSON format doesn't support non-string as key type of map. \"\n                            + \"The type is: \"\n                            + typeSummary);","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonParserToRowDataConverters.java#L336-L372","documentation":"IllegalStateException from createArrayConverter's lambda when the current token is not START_ARRAY while converting an ARRAY column — i.e., the JSON value at that position is a scalar/object where the schema expects '[' ... ']'. It indicates a data-shape mismatch, not parser corruption.","triggerScenarios":"Schema says ARRAY<...> but the payload has \"tags\": \"a,b\" or \"tags\": {\"a\":1}; also nested arrays where the element converter hits a non-array token.","commonSituations":"Producers sometimes emitting a single value instead of a list for one-element arrays; schema evolution from scalar to array; hand-written DDL guessing the wrong shape.","solutions":["Align the DDL with the real payload shape (STRING instead of ARRAY, or ARRAY if data is consistently a list)","Fix the producer to always emit an array, even for single elements","Sample the topic/files with the actual JSON to confirm the field's real shape before fixing the schema"],"exampleFix":"-- before\ntags ARRAY<STRING>   -- data is \"tags\": \"a,b\"\n\n-- after\ntags STRING","handlingStrategy":"validation","validationCode":"// sample check: field declared ARRAY must always be a JSON array\nJsonNode n = mapper.readTree(sample).get(\"tags\");\nif (!n.isArray()) throw new IllegalStateException(\"tags must be an array in every record\");","typeGuard":null,"tryCatchPattern":"catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Illegal JSON array data\")) {\n        // payload shape != ARRAY<...> in DDL; align schema or producer\n    }\n}","preventionTips":["Validate a representative sample of records against the DDL before deploying","Make producers emit consistent shapes (always arrays for list fields)"],"tags":["flink","json","array","schema-mismatch","data-quality"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}