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

**Code:** `json: cannot unmarshal string into Go struct field` · **Category:** Go · **Seen on:** Go

The JSON value's type does not match the Go field type (string vs number, object vs array).

## Meaning

The error names the field and both types. Fix the struct (use `string`, `json.Number`, or a custom type), fix the data source, or add the `,string` tag option when numbers arrive as quoted strings. Since Go 1.20 decoding continues past this error for other fields but returns the first error.

## Common causes

- API returns "30" (string) but field is int
- Object returned where array expected
- null into non-pointer scalar
- Field name/tag mismatch leaving zero values
- Unexported fields never populated

## Quick fix

1. Change the field type or use `json:"age,string"`
2. Use `json.RawMessage` or `interface{}` for variable shapes
3. Inspect the raw payload first

## Detailed fix by platform

### Go

1. `type User struct { Age int `json:"age,string"` }` accepts `"age":"30"`

## How to diagnose

1. **Field** — Named in message?
2. **JSON** — Actual type?
3. **Tag** — Matches key?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/json-unmarshal-string-into-struct-field)
