# Expecting value: line 1 column 1 (char 0) in Python

> Fix Expecting value: line 1 column 1 (char 0) in Python: read the position, inspect the requests response or the file, and parse only real JSON.

- URL: https://jsonstatham.dev/errors/expecting-value/
- Language: English (en)
- Russian version: https://jsonstatham.dev/ru/errors/expecting-value.md
- Updated: 2026-11-08

`json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)` means Python’s `json` module looked for a value at the first character and found nothing it recognizes. The text is empty, or it starts with something that isn’t JSON. From requests the same error reads `requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)`, and there it nearly always means the server didn’t send JSON. Python looked. There was nothing to find.

## Read the position first

`Expecting value` is raised wherever a value should begin: at the start, after a colon, after a comma or `[`. The position tells you which case you have. `char` counts characters from 0; `line` and `column` count from 1, so `char 0` is line 1, column 1. Checked on Python 3.9.6 and 3.14.10:

| Message ends with | What is at that spot | Next step |
| --- | --- | --- |
| `line 1 column 1 (char 0)`, the text is empty | Nothing: an empty response or file, or a file object that was already read | [Responses](https://jsonstatham.dev/errors/expecting-value/#requests), [files](https://jsonstatham.dev/errors/expecting-value/#files) |
| `line 1 column 1 (char 0)`, the text is not empty | Not JSON: an HTML page (`<`), an error message, `None`, `undefined` | [Unexpected token '<'](https://jsonstatham.dev/errors/unexpected-token/) |
| `line 2 column 1 (char 1)` on a single line break | Whitespace only, such as the blank last line of a JSON Lines file | [JSON Lines](https://jsonstatham.dev/guides/json-lines/) |
| `line 1 column 8 (char 7)` in `{"ok": True}` | A Python literal where a JSON value belongs: `True`, `None` | [Invalid literal](https://jsonstatham.dev/errors/invalid-literal/) |
| `line 1 column 10 (char 9)` in `{"name": 'Ada'}` | A string in single quotes | [Single quotes](https://jsonstatham.dev/errors/single-quotes/) |
| `line 1 column 7 (char 6)` in `[1, 2,]`, Python 3.12 and older | A trailing comma. Python 3.13 and later report `Illegal trailing comma before end of array` instead | [Trailing comma](https://jsonstatham.dev/errors/trailing-comma/) |

In the terms of [RFC 8259](https://www.rfc-editor.org/rfc/rfc8259), `JSON-text = ws value ws`: after optional whitespace a value must follow, one of `false`, `null`, `true`, an object, an array, a number or a string. Empty text has none, and `<`, `T` or `'` start none of them.

## With requests: look at the response first

`response.json()` checks neither the status nor the content type: it parses whatever came back. Print what came back:

```python
import requests

r = requests.get(url, timeout=10)
print(r.status_code, r.headers.get("Content-Type"), len(r.content))
print(r.history, r.url)
print(r.text[:300])
```

- `204` and a length of `0`: there is no body. Don’t call `.json()` on a 204.
- `200 text/html` with a non-empty `r.history`: requests followed a redirect, usually to a login page.
- `403 text/html`: a firewall or bot check. Your script lacks a header, cookie or token that the browser sends.
- `500`, `502` or `503` with HTML or text: the server failed, and the body says how.
- `200 application/json` and the error anyway: the body is empty or broken. Use the position table above.

Since requests 2.27, `requests.exceptions.JSONDecodeError` inherits from both `json.JSONDecodeError` and `requests.RequestException`, so either `except` clause catches it, and it is still a `ValueError`. httpx 0.28.1 raises the plain `json.JSONDecodeError`. aiohttp 3.13.5 checks the content type first and raises `ContentTypeError: 200, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8'` without parsing at all.

The fix is the same check as in any language: status and type before parsing. Run against a test server answering JSON, HTML, an HTML 500 and an empty 204:

```python
import requests

def get_json(url, **kwargs):
    r = requests.get(url, timeout=10, **kwargs)
    ctype = r.headers.get("Content-Type", "")
    if r.ok and "json" in ctype:
        return r.json()
    raise RuntimeError(f"{r.status_code} {ctype} from {r.url}: {repr(r.text[:200])}")
```

## With files: check what you actually opened

- **An empty file.** `os.path.getsize(path)` is 0: something created the file and never wrote it, or a crash left it truncated.
- **A file you already read.** After `f.read()` the position is at the end, so `json.load(f)` sees an empty string and fails at `char 0`. Call `f.seek(0)` or parse the text you already have.
- **The wrong file.** A relative path resolved against another working directory, or a web page saved as `.json`: a GitHub link with `/blob/` in it downloads the page around the file, not the file.
- **A byte order mark** has its own message, `Unexpected UTF-8 BOM (decode using utf-8-sig)`. Open the file with `encoding="utf-8-sig"`; see [BOM](https://jsonstatham.dev/errors/bom/).

```python
import json
from pathlib import Path

path = Path("data.json")
raw = path.read_bytes()
print(path.resolve(), len(raw), raw[:80])
data = json.loads(raw.decode("utf-8-sig"))
```

The three printed values answer which file was opened, how big it is and how it starts; decoding with `utf-8-sig` also drops a byte order mark if there is one. From the shell, `python -m json.tool data.json` prints the same message with the position, and Python 3.14 also accepts the shorter `python -m json`. See the [json module documentation](https://docs.python.org/3/library/json.html#module-json.tool).

## The same input in other languages

Python’s message is the vaguest of the common parsers: an empty body, a web page and a Python literal all produce `Expecting value`. Other languages name the character, which helps when all you have is a log line:

| Input | Python 3.9.6 and 3.14.10 | JavaScript, V8 (Node.js 25.1) | Go 1.25.3 |
| --- | --- | --- | --- |
| empty | `Expecting value: line 1 column 1 (char 0)` | `Unexpected end of JSON input` | `unexpected end of JSON input` |
| an HTML page | `Expecting value: line 1 column 1 (char 0)` | `Unexpected token '<', "<!DOCTYPE "... is not valid JSON` | `invalid character '<' looking for beginning of value` |
| `None` | `Expecting value: line 1 column 1 (char 0)` | `Unexpected token 'N', "None" is not valid JSON` | `invalid character 'N' looking for beginning of value` |
| `{"ok": True}` | `Expecting value: line 1 column 8 (char 7)` | `Unexpected token 'T', "{"ok": True}" is not valid JSON` | `invalid character 'T' looking for beginning of value` |
| `{"name": 'Ada'}` | `Expecting value: line 1 column 10 (char 9)` | `Unexpected token ''', "{"name": 'Ada'}" is not valid JSON` | `invalid character '\'' looking for beginning of value` |

## Prevent it

- Wrap HTTP calls in one function that checks the status and type before `.json()`, like `get_json` above.
- Write files atomically: `json.dump` into a temporary file, then `os.replace` it over the old one. Readers never see an empty or half-written file.
- Skip blank lines when reading [JSON Lines](https://jsonstatham.dev/guides/json-lines/): `if line.strip():`.
- In pipelines, check `returncode` before parsing `stdout`: a failed command writes to stderr and leaves stdout empty.
- Catch [`json.JSONDecodeError`](https://docs.python.org/3/library/json.html#json.JSONDecodeError) where the text enters your program and log `e.pos` with the first 200 characters, so the report carries the evidence.

## Try it

Paste the text into the [validator](https://jsonstatham.dev/validator/?sample=unexpected_character) to see the first bad character named, with its line and column. In a long document, [the position finder](https://jsonstatham.dev/json-position/) turns `char 18734` into a line and column and shows the spot.

Related: [Expecting property name enclosed in double quotes](https://jsonstatham.dev/errors/expecting-property-name/), [Unexpected token '<'](https://jsonstatham.dev/errors/unexpected-token/), [Unexpected end of JSON input](https://jsonstatham.dev/errors/unexpected-end-of-json-input/), and the [list of JSON errors](https://jsonstatham.dev/errors/).

## Expecting value FAQ

### What does “Expecting value: line 1 column 1 (char 0)” mean?

Python found no JSON value at the very first character. The text is empty, or it starts with something that is not JSON, most often an HTML page from a server.

### Why does response.json() fail when the request succeeded?

A 200 status says nothing about the body. It can be a login page after a redirect, or nothing at all. Print `r.status_code`, `r.headers.get("Content-Type")` and `r.text[:300]` before parsing.

### How do I catch this error?

Catch `json.JSONDecodeError`; with requests, `requests.exceptions.JSONDecodeError` works too. Both are subclasses of `ValueError`, so older code that catches `ValueError` keeps working.

### Is “char 0” the first character?

Yes. `char` is a zero-based index into the text, while `line` and `column` start at 1. The exception carries all three as `e.pos`, `e.lineno` and `e.colno`.
