Go: invalid character '<' looking for beginning of value
The decoder received something that is not JSON — often an HTML error page, an empty body or plain text.
invalid character '<' looking for beginning of valueinvalid character 'N' looking for beginning of valueinvalid character '}' looking for beginning of object key stringunexpected end of JSON inputinvalid character ' ' in numeric literal Meaning
The character in the message hints at the content: < means HTML, ' means single-quoted JSON, a letter means plain text such as "Not Found", } or , means broken JSON. Log the response body and status code before decoding, and check Content-Type.
Common causes
- HTML error page (404/500/login redirect) decoded as JSON
- Empty body (EOF)
- Plain-text error message
- Single quotes or trailing commas in JSON
- BOM or compressed (gzip) content not decoded
⚡ Quick fix
- Print
resp.StatusCodeand the body before decoding - Check
Content-Type: application/json - Verify the URL and authentication
Detailed fix by platform
Go
body, _ := io.ReadAll(resp.Body); log.Printf("%d %s", resp.StatusCode, body)
How to diagnose
- Char — What starts the body?
- Status — 200?
- URL — Correct endpoint?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- assignment mismatch: 1 variable but f returns 2 values Go: assignment mismatch: 1 variable but os.Open returns 2 values
- cannot assign to struct field m[k].f in map Go: cannot assign to struct field users["bob"].Age in map
- dial tcp: connect: connection refused Go: dial tcp 127.0.0.1:5432: connect: connection refused
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026