# Go: invalid character '<' looking for beginning of value

**Code:** `invalid character looking for beginning of value` · **Category:** Go · **Seen on:** Go

The decoder received something that is not JSON — often an HTML error page, an empty body or plain text.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/json-invalid-character)
