# json: cannot unmarshal string into Go struct field Foo.Bar of type map[string]string

- **ID:** `go/cannot-unmarshal-string-into-struct-field-of-type-map`
- **Domain:** go
- **Category:** encoding_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

JSON contains a string value where the Go struct expects a map, due to incorrect JSON structure or type mismatch in the source data.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| go1.20 | active | — | — |
| go1.21 | active | — | — |
| go1.22 | active | — | — |

## Workarounds

1. **Change Go struct field type to string and parse manually: type Foo struct { Bar string } then unmarshal Bar as JSON string into map.** (90% success)
   ```
   Change Go struct field type to string and parse manually: type Foo struct { Bar string } then unmarshal Bar as JSON string into map.
   ```
2. **Preprocess JSON to ensure Bar is an object: use json.RawMessage to capture Bar, then check if it's a string and handle accordingly.** (85% success)
   ```
   Preprocess JSON to ensure Bar is an object: use json.RawMessage to capture Bar, then check if it's a string and handle accordingly.
   ```

## Dead Ends

- **** — Tags only affect naming, not type conversion. (70% fail)
- **** — UseNumber() only affects number parsing, not type coercion. (80% fail)
