googleapis/mcp-toolbox · error
unable to unmarshal json data %s
Error message
unable to unmarshal json data %s
What it means
json.Unmarshal failed on the []byte value of a JSON-typed column in RunSQL — the bytes stored in the TiDB JSON column are not valid JSON, so they cannot be decoded into a Go value.
Source
Thrown at internal/sources/tidb/tidb.go:163
val := rawValues[i]
if val == nil {
vMap[name] = nil
continue
}
// mysql driver return []uint8 type for "TEXT", "VARCHAR", and "NVARCHAR"
// we'll need to cast it back to string
switch colTypes[i].DatabaseTypeName() {
case "JSON":
// unmarshal JSON data before storing to prevent double
// marshaling
byteVal, ok := val.([]byte)
if !ok {
return nil, fmt.Errorf("expected []byte for JSON column, but got %T", val)
}
var unmarshaledData any
if err := json.Unmarshal(byteVal, &unmarshaledData); err != nil {
return nil, fmt.Errorf("unable to unmarshal json data %s", val)
}
vMap[name] = unmarshaledData
case "TEXT", "VARCHAR", "NVARCHAR":
byteVal, ok := val.([]byte)
if !ok {
return nil, fmt.Errorf("expected []byte for text-like column, but got %T", val)
}
vMap[name] = string(byteVal)
default:
vMap[name] = val
}
}
out = append(out, vMap)
}
if err := results.Err(); err != nil {
return nil, fmt.Errorf("errors encountered during row iteration: %w", err)
}View on GitHub (pinned to 8cc6e09de2)
Solutions
- Inspect the raw column value shown in the error
- Fix the malformed JSON stored in the row
- Cast the column to CHAR in the query if it is not truly JSON
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at internal/sources/tidb/tidb.go:163 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/8bf88670ec8914b1.
Report an issue: GitHub.