# json: cannot unmarshal number into Go struct field User.age of type string

- **ID:** `go/json-cannot-unmarshal-number-into-string`
- **Domain:** go
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The JSON payload contains a numeric value where the Go struct expects a string. The API changed, or the schema was misdeclared.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |
| 1.22 | active | — | — |

## Workarounds

1. **** (88% success)
   ```
   type User struct {
  Age json.Number `json:"age"`
}
dec := json.NewDecoder(r)
dec.UseNumber()
dec.Decode(&u)
   ```
2. **** (85% success)
   ```
   Define a custom type with UnmarshalJSON that accepts both string and number.
   ```

## Dead Ends

- **** — Loses type safety and just moves the panic downstream when the value is used. (60% fail)
- **** — Leaves partially populated struct and hides real data corruption. (75% fail)
