{"record":{"id":"8148850083d97d1b","repo":"googleapis/mcp-toolbox","slug":"unable-to-unmarshal-json-data-for-column-s","errorCode":null,"errorMessage":"unable to unmarshal json data for column %s","messagePattern":"unable to unmarshal json data for column (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/oracle/oracle.go","lineNumber":242,"sourceCode":"\t\t\t\t\tvMap[col] = nil\n\t\t\t\t}\n\t\t\tcase *sql.NullString:\n\t\t\t\tif v.Valid {\n\t\t\t\t\tvMap[col] = v.String\n\t\t\t\t} else {\n\t\t\t\t\tvMap[col] = nil\n\t\t\t\t}\n\t\t\tcase *sql.NullTime:\n\t\t\t\tif v.Valid {\n\t\t\t\t\tvMap[col] = v.Time\n\t\t\t\t} else {\n\t\t\t\t\tvMap[col] = nil\n\t\t\t\t}\n\t\t\tcase *sql.RawBytes:\n\t\t\t\tif *v != nil {\n\t\t\t\t\tvar unmarshaledData any\n\t\t\t\t\tif err := json.Unmarshal(*v, &unmarshaledData); err != nil {\n\t\t\t\t\t\treturn nil, fmt.Errorf(\"unable to unmarshal json data for column %s\", col)\n\t\t\t\t\t}\n\t\t\t\t\tvMap[col] = unmarshaledData\n\t\t\t\t} else {\n\t\t\t\t\tvMap[col] = nil\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"unexpected receiver type: %T\", v)\n\t\t\t}\n\t\t}\n\t\tout = append(out, vMap)\n\t}\n\n\tif err := rows.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"errors encountered during query execution or row processing: %w\", err)\n\t}\n\n\treturn out, nil\n}","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/oracle/oracle.go#L224-L260","documentation":"This error occurs when a column typed as Oracle JSON was scanned into sql.RawBytes but its bytes are not valid JSON, so json.Unmarshal fails. RunSQL routes columns whose DatabaseTypeName() is \"JSON\" into a RawBytes receiver and parses them to return structured JSON rather than a raw string. Note the column name is interpolated but the underlying unmarshal error is not included in the message.","triggerScenarios":"RunSQL (readOnly=true) selecting from a column reported as type JSON whose content is malformed or truncated (e.g. a value stored via legacy paths, truncated by max byte limits, or a driver that reports JSON for a VARCHAR2 column containing non-JSON text).","commonSituations":"Oracle 21c+ JSON-type columns populated with invalid data before a CHECK 'IS JSON' constraint existed; middleware truncating large JSON documents; a go-ora driver mislabeling a VARCHAR2/CLOB as JSON; hand-inserted strings into an IS-JSON disabled column.","solutions":["Inspect the offending column's value for that row — validate it with SELECT JSON_SERIALIZE(col) or check IS JSON to find corrupt rows.","Cast the column to a string in the query (e.g. TO_CHAR(col) or col) via a non-JSON alias so it is returned as text instead of being unmarshaled.","Add or fix the CHECK (col IS JSON) constraint to prevent invalid JSON from being stored.","Check for byte truncation (network MTU, LOB fetch limits, driver LOB settings) that could cut JSON payloads mid-document.","Upgrade go-ora/godror if a known bug reports wrong type names for VARCHAR2 columns holding JSON."],"exampleFix":"// before: returns invalid column value as text\ncol varchar2(4000) = '{broken'\n\n// after: enforce JSON at the schema level\nALTER TABLE t ADD CONSTRAINT t_json_chk CHECK (jcol IS JSON);","handlingStrategy":"validation","validationCode":"SELECT COUNT(*) FROM t WHERE NOT jcol IS JSON;\n-- returns rows containing invalid JSON; fix or exclude them before querying through RunSQL","typeGuard":null,"tryCatchPattern":"out, err := source.RunSQL(ctx, stmt, params, true)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to unmarshal json data for column\") {\n        col := extractColName(err.Error())\n        // fall back: re-query casting the JSON column to a plain string\n        return source.RunSQL(ctx, \"SELECT TO_CHAR(\"+col+\") AS \"+col+\", ... FROM ...\", params, true)\n    }\n    return err\n}","preventionTips":["Add CHECK (col IS JSON) constraints to all JSON-typed columns.","Never disable IS-JSON validation on bulk inserts into JSON columns.","Verify LOB fetch limits won't truncate large JSON documents.","Test JSON columns with JSON_SERIALIZE to detect corrupt rows early."],"tags":["oracle","json","unmarshal","data-integrity"],"backgroundTag":"invalid-json-payload","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}