{"record":{"id":"ad7d1baed99d97c7","repo":"apache/cassandra","slug":"error-decoding-json-string","errorCode":null,"errorMessage":"Error decoding JSON string: ","messagePattern":"Error decoding JSON string: ","errorType":"exception","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/utils/JsonUtils.java","lineNumber":101,"sourceCode":"        try\n        {\n            return JSON_OBJECT_MAPPER.readValue(json, Object.class);\n        }\n        catch (IOException ex)\n        {\n            throw new MarshalException(\"Error decoding JSON bytes: \" + ex.getMessage());\n        }\n    }\n\n    public static Object decodeJson(String json)\n    {\n        try\n        {\n            return JSON_OBJECT_MAPPER.readValue(json, Object.class);\n        }\n        catch (IOException ex)\n        {\n            throw new MarshalException(\"Error decoding JSON string: \" + ex.getMessage());\n        }\n    }\n\n    public static byte[] writeAsJsonBytes(Object value)\n    {\n        try\n        {\n            return JSON_OBJECT_MAPPER.writeValueAsBytes(value);\n        }\n        catch (IOException ex)\n        {\n            throw new MarshalException(\"Error writing as JSON: \" + ex.getMessage());\n        }\n    }\n\n    public static String writeAsJsonString(Object value)\n    {\n        try","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/utils/JsonUtils.java#L83-L119","documentation":"JsonUtils.decodeJson(String) parses a JSON string with Jackson. On any Jackson IOException (malformed JSON, unexpected token, encoding issue) it wraps the cause in MarshalException 'Error decoding JSON string: <message>'.","triggerScenarios":"Calling JsonUtils.decodeJson(String) with malformed JSON such as single-quoted strings, trailing commas, unquoted keys, or empty/whitespace strings.","commonSituations":"Hand-edited JSON passed programmatically; JSON produced by non-Jackson serializers with syntax extensions; empty column values treated as JSON.","solutions":["Validate/normalize the JSON string before decoding (use a strict JSON producer)","Check the string is non-empty and well-formed; log it on failure to spot the syntax issue","Catch MarshalException and return a default or surface a user-friendly parse error"],"exampleFix":"// before\nObject v = JsonUtils.decodeJson(\"{'a':1}\"); // invalid JSON\n// after\nObject v = JsonUtils.decodeJson(\"{\\\"a\\\":1}\");","handlingStrategy":"try-catch","validationCode":"if (json == null || json.trim().isEmpty()) throw new IllegalArgumentException(\"empty JSON string\");","typeGuard":null,"tryCatchPattern":"try { return JsonUtils.decodeJson(json); } catch (MarshalException e) { logger.warn(\"Bad JSON: {}\", json); throw new InvalidRequestException(e.getMessage()); }","preventionTips":["Never hand-build JSON with string concatenation; use writeAsJsonString","Reject empty/whitespace strings before decoding","Log the offending string (safely truncated) when a MarshalException occurs"],"tags":["json","jackson","decoding"],"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-17T15:17:12.973Z"}