invalid character looking for beginning of value Go Origin: Application & API OSI layer 6 · Presentation Last updated 4 Nov 2026

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.

Exact message you may see 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
Seen on: Go

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

  1. Print resp.StatusCode and the body before decoding
  2. Check Content-Type: application/json
  3. Verify the URL and authentication

Detailed fix by platform

Go

  1. body, _ := io.ReadAll(resp.Body); log.Printf("%d %s", resp.StatusCode, body)

How to diagnose

  1. Char — What starts the body?
  2. Status — 200?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

assignment mismatch: 1 variable but f returns 2 values — Go: assignment mismatch: 1 variable but os.Open returns 2 values (Go)assignment mismatch: …cannot assign to struct field m[k].f in map — Go: cannot assign to struct field users["bob"].Age in map (Go)cannot assign to stru…dial tcp: connect: connection refused — Go: dial tcp 127.0.0.1:5432: connect: connection refused (Go)dial tcp: connect: co…http: superfluous response.WriteHeader call — Go: http: superfluous response.WriteHeader call from main.handler (main.go:25) (Go)http: superfluous res…json: cannot unmarshal string into Go struct field — Go: json: cannot unmarshal string into Go struct field User.age of type int (Go)json: cannot unmarsha…listen tcp :8080: bind: address already in use — Go: listen tcp :8080: bind: address already in use (Go)listen tcp :8080: bin…panic: assignment to entry in nil map — Go: panic: assignment to entry in nil map (Go)panic: assignment to …x509: certificate signed by unknown authority — Go: x509: certificate signed by unknown authority (Go)x509: certificate sig…invalid c…

Explore the map of this error Full error map →

🧠 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.