{"record":{"id":"22055d127d3109e6","repo":"apache/cassandra","slug":"error-decoding-json-value-for-s-s","errorCode":null,"errorMessage":"Error decoding JSON value for %s: %s","messagePattern":"Error decoding JSON value for (.+?): (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Json.java","lineNumber":304,"sourceCode":"                // explicit null value from no value\n                if (!valueMap.containsKey(spec.name.toString()))\n                    continue;\n\n                Object parsedJsonObject = valueMap.remove(spec.name.toString());\n                if (parsedJsonObject == null)\n                {\n                    // This is an explicit user null\n                    columnMap.put(spec.name, Constants.NULL_VALUE);\n                }\n                else\n                {\n                    try\n                    {\n                        columnMap.put(spec.name, spec.type.fromJSONObject(parsedJsonObject));\n                    }\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        {","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Json.java#L286-L322","documentation":"Json.parseJson wraps per-column decode failures in this InvalidRequestException: the JSON value for a recognized column could not be converted to the column's type by spec.type.fromJSONObject. The MarshalException message (e.g. wrong type, out-of-range number, bad format) is appended after the column name.","triggerScenarios":"INSERT INTO t JSON with a value that doesn't match the column type — a string where an int is expected, a malformed timestamp/uuid, a number too large for the column type, an invalid nested collection element.","commonSituations":"Sending ISO date strings where Cassandra expects its timestamp format; floats for decimal/int columns; JSON numbers exceeding column range; passing objects for non-collection columns; duration/tuple columns given string values in wrong internal format.","solutions":["Read the appended MarshalException message for the exact per-column reason","Match JSON value types to schema: quoted strings for timestamps/uuids/durations, numbers within range for numeric columns","Use toJson() on existing rows to see the exact JSON shape Cassandra accepts","Validate payloads against the table schema (SystemSchema/describe) before insert"],"exampleFix":"// before\n{\"created\": \"2026-09-09T10:00:00Z\"} // if timestamp format rejected\n// after\n{\"created\": \"2026-09-09 10:00:00+0000\"} // use Cassandra-accepted format","handlingStrategy":"try-catch","validationCode":"// validate one value against its column type before INSERT JSON\nspec.type.parse(rawJsonStringForValue); // throws InvalidRequest on mismatch","typeGuard":null,"tryCatchPattern":"try { session.execute(\"INSERT INTO t JSON ?\", json); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Error decoding JSON value for\")) { String col = e.getMessage().split(\"for \")[1].split(\":\")[0].trim(); throw new IllegalArgumentException(\"Bad value for column \" + col, e); } throw e; }","preventionTips":["Match JSON value types to column types (strings for timestamp/uuid/duration)","Use toJson() output of existing rows as the canonical payload shape","Check numeric ranges against column types before sending","Generate payloads from the live schema, not hardcoded templates"],"tags":["cql","json","type-mismatch"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}