{"record":{"id":"e56b5fc6d7702028","repo":"apache/cassandra","slug":"could-not-decode-json-string-as-a-map-s-string","errorCode":null,"errorMessage":"Could not decode JSON string as a map: %s. (String was: %s)","messagePattern":"Could not decode JSON string as a map: (.+?)\\. \\(String was: (.+?)\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Json.java","lineNumber":319,"sourceCode":"                    }\n                    catch (MarshalException exc)\n                    {\n                        throw new InvalidRequestException(format(\"Error decoding JSON value for %s: %s\", spec.name, exc.getMessage()));\n                    }\n                }\n            }\n\n            if (!valueMap.isEmpty())\n            {\n                throw new InvalidRequestException(format(\"JSON values map contains unrecognized column: %s\",\n                                                         valueMap.keySet().iterator().next()));\n            }\n\n            return columnMap;\n        }\n        catch (IOException exc)\n        {\n            throw new InvalidRequestException(format(\"Could not decode JSON string as a map: %s. (String was: %s)\", exc.toString(), jsonString));\n        }\n        catch (MarshalException exc)\n        {\n            throw new InvalidRequestException(exc.getMessage());\n        }\n    }\n}\n","sourceCodeStart":301,"sourceCodeEnd":327,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Json.java#L301-L327","documentation":"Json.parseJson catches IOException from the Jackson ObjectMapper and rethrows it as this InvalidRequestException, meaning the string could not be decoded as a JSON map at all. The original exception toString and the offending input string are included for diagnosis.","triggerScenarios":"Passing syntactically invalid JSON to INSERT INTO t JSON '...' or a bound JSON parameter: unquoted keys, trailing commas, single quotes, truncated documents, or non-JSON text.","commonSituations":"Hand-writing JSON with single-quoted strings; concatenating payloads that truncate; logs/templating injecting garbage; reading the JSON from a file or queue with corruption; passing a Java Map's toString() instead of real JSON.","solutions":["Validate the JSON string with a JSON parser/validator before executing the statement","Fix syntax: double quotes for keys and strings, no trailing commas, no single quotes","If the value is a Java object, serialize it with a JSON library rather than string concatenation","Check upstream producers (queues, files, APIs) for truncated or corrupted payloads"],"exampleFix":"// before\nString json = \"{'a': 1,}\";\n// after\nString json = \"{\\\"a\\\": 1}\";","handlingStrategy":"validation","validationCode":"private static void requireValidJson(String json) {\n    try { new ObjectMapper().readTree(json); }\n    catch (IOException e) { throw new IllegalArgumentException(\"Not valid JSON: \" + e.getMessage(), e); }\n}","typeGuard":null,"tryCatchPattern":"try { session.execute(\"INSERT INTO t JSON ?\", json); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Could not decode JSON string\")) { log.error(\"Bad JSON: {}\", json, e); throw new IllegalArgumentException(\"Malformed JSON payload\", e); } throw e; }","preventionTips":["Validate JSON with a parser before executing statements","Use double quotes exclusively; no trailing commas","Serialize objects with a JSON library, never string concatenation","Check upstream data sources for truncation/corruption"],"tags":["cql","json","parsing"],"backgroundTag":"json-parse-error","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}