{"record":{"id":"46ae3b5fdbc9333f","repo":"apache/flink","slug":"json-format-doesn-t-support-non-string-as-key-type","errorCode":null,"errorMessage":"JSON format doesn't support non-string as key type of map. The type is: {}","messagePattern":"JSON format doesn't support non-string as key type of map\\. The type is: (.+?)","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonParserToRowDataConverters.java","lineNumber":369,"sourceCode":"                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);\n        }\n        final JsonParserToRowDataConverter keyConverter = createConverter(keyType);\n        final JsonParserToRowDataConverter valueConverter = createConverter(valueType);\n\n        return jp -> {\n            if (jp.currentToken() != JsonToken.START_OBJECT) {\n                throw new IllegalStateException(\"Illegal JSON map data...\");\n            }\n            Map<Object, Object> result = new HashMap<>();\n            while (jp.nextToken() != JsonToken.END_OBJECT) {\n                Object key = keyConverter.convert(jp);\n                jp.nextToken();\n                Object value = valueConverter.convert(jp);\n                result.put(key, value);\n            }","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonParserToRowDataConverters.java#L351-L387","documentation":"UnsupportedOperationException from createMapConverter when the map key type is not in the CHARACTER_STRING family. JSON object keys are always strings, so a MAP<INT, ...> or MAP<BIGINT, ...> column cannot be populated from JSON and the converter refuses to be created (fail-fast at schema build, before any record is read).","triggerScenarios":"DDL declaring MAP<INT, T> / MAP<BIGINT, T> / MAP<DATE, T> etc. for a JSON table using the parser-based deserializer; also MAP<STRING,...> is fine, MAP with any non-string key type is not.","commonSituations":"Porting a schema from a format that allows typed keys (Avro maps always have string keys, but Parquet/Row-based tools may suggest typed ones); auto-derived schemas producing numeric keys.","solutions":["Change the key type to STRING: MAP<STRING, T> and cast keys downstream (CAST or a UDF) if numeric semantics are needed","Or restructure the data as an ARRAY<ROW<key T, value U>>","For lookups by typed key, normalize keys to strings at the producer"],"exampleFix":"-- before\nids MAP<BIGINT, STRING>\n\n-- after\nids MAP<STRING, STRING>","handlingStrategy":"validation","validationCode":"if (!mapType.getKeyType().is(LogicalTypeFamily.CHARACTER_STRING)) {\n    throw new UnsupportedOperationException(\"Use MAP<STRING, ...> for JSON\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always declare JSON map keys as STRING and cast downstream","For typed keys, model as ARRAY<ROW<key, value>> instead"],"tags":["flink","json","map","schema","converter"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}