{"record":{"id":"2c4fab762673a0ea","repo":"googleapis/mcp-toolbox","slug":"expected-byte-for-json-column-but-got-t","errorCode":null,"errorMessage":"expected []byte for JSON column, but got %T","messagePattern":"expected \\[\\]byte for JSON column, but got %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/tidb/tidb.go","lineNumber":159,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"unable to parse row: %w\", err)\n\t\t}\n\t\tvMap := make(map[string]any)\n\t\tfor i, name := range cols {\n\t\t\tval := rawValues[i]\n\t\t\tif val == nil {\n\t\t\t\tvMap[name] = nil\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// mysql driver return []uint8 type for \"TEXT\", \"VARCHAR\", and \"NVARCHAR\"\n\t\t\t// we'll need to cast it back to string\n\t\t\tswitch colTypes[i].DatabaseTypeName() {\n\t\t\tcase \"JSON\":\n\t\t\t\t// unmarshal JSON data before storing to prevent double\n\t\t\t\t// marshaling\n\t\t\t\tbyteVal, ok := val.([]byte)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, fmt.Errorf(\"expected []byte for JSON column, but got %T\", val)\n\t\t\t\t}\n\t\t\t\tvar unmarshaledData any\n\t\t\t\tif err := json.Unmarshal(byteVal, &unmarshaledData); err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"unable to unmarshal json data %s\", val)\n\t\t\t\t}\n\t\t\t\tvMap[name] = unmarshaledData\n\t\t\tcase \"TEXT\", \"VARCHAR\", \"NVARCHAR\":\n\t\t\t\tbyteVal, ok := val.([]byte)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, fmt.Errorf(\"expected []byte for text-like column, but got %T\", val)\n\t\t\t\t}\n\t\t\t\tvMap[name] = string(byteVal)\n\t\t\tdefault:\n\t\t\t\tvMap[name] = val\n\t\t\t}\n\t\t}\n\t\tout = append(out, vMap)\n\t}","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/tidb/tidb.go#L141-L177","documentation":"RunSQL's JSON-column branch found that the scanned value for a JSON-typed column is not []byte as the MySQL driver normally returns — the type assertion val.([]byte) failed, so the JSON cannot be unmarshaled.","triggerScenarios":"Thrown at internal/sources/tidb/tidb.go:159 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the actual Go type reported by %T in the message","Avoid driver/server combos that return JSON columns as other types","Handle or convert the value before the branch"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}