Skip to content
JSON Tidy

Broken and tricky JSON for testing

Each URL below returns a response that trips up JSON parsing in its own way. Point your app or test suite at one to check its error handling, or press Send request to see what await response.json() does with it in your browser. The error you see is the real one, from your browser’s own parser.

Broken responses

None of these will parse as JSON. Most are mistakes that happen in real systems: a proxy returning its own error page, a service printing a Python dict, a config file with comments.

Empty body

Status 200 and a JSON content type, but nothing in the body. Servers do this when something fails after the headers have gone out.

GET/api/test-json/empty-body

Explained in Unexpected end of JSON input.

HTML instead of JSON

An HTML page with status 200. It’s what you often get from a wrong API URL, when a single-page app’s fallback route or a login page answers instead.

GET/api/test-json/html-error-page

Explained in Unexpected token < in JSON.

Error page from a proxy

A 502 with an HTML body, the kind a load balancer or proxy returns when the API behind it is down.

GET/api/test-json/server-error-html

Explained in Unexpected token < in JSON.

Cut off partway

The response stops in the middle of a string, as if the connection dropped or a size limit was hit.

GET/api/test-json/truncated

Explained in Unexpected end of JSON input.

Trailing comma

A comma after the last item in an array and the last property in an object. JavaScript allows it in code; JSON doesn’t.

GET/api/test-json/trailing-comma

Explained in Trailing commas in JSON.

Single quotes and unquoted keys

JavaScript object syntax instead of JSON: keys without quotes and strings in single quotes.

GET/api/test-json/single-quotes

Explained in Expecting property name enclosed in double quotes.

Python dict printed with str()

What you get when a Python service sends str(data) instead of json.dumps(data): single quotes, True and None.

GET/api/test-json/python-repr

Explained in Expecting property name enclosed in double quotes.

NaN and Infinity

Python’s json.dumps writes these by default for float("nan") and float("inf"), but they aren’t valid JSON.

GET/api/test-json/nan

Explained in JSON error lookup.

Comments

A config file with // and /* */ comments. Fine for tsconfig.json and VS Code, an error for JSON.parse.

GET/api/test-json/comments

Explained in JSONC to JSON.

Two JSON values in one body

Two objects one after the other, as in newline-delimited JSON (NDJSON) or a log file. Each line is valid; the whole body isn’t.

GET/api/test-json/two-documents

Explained in Extra data.

Line break inside a string

A real line break and a tab inside a string value, where JSON needs \n and \t.

GET/api/test-json/control-character

Explained in Bad control character in string literal.

Byte order mark at the start

Valid JSON with an invisible byte order mark (BOM) in front, as Windows tools often save it. Some parsers skip it, others fail on the first character.

GET/api/test-json/bom

Explained in Python: Unexpected UTF-8 BOM.

JSON sent as text/plain

Valid JSON, but with Content-Type: text/plain. Clients that check the header before parsing will refuse it.

GET/api/test-json/wrong-content-type

Valid, but tricky

These all parse, but each one breaks code that makes an assumption about the data, like every number fitting in a JavaScript number or there always being a first item.

Numbers too big for JavaScript

Valid JSON. JSON.parse rounds the IDs past 2^53, so two different runs end up with the same ID, and 1e400 becomes Infinity.

GET/api/test-json/big-numbers

Explained in JSON viewer (shows numbers exactly).

The same key twice

The JSON spec allows it, but most parsers quietly keep only the last value.

GET/api/test-json/duplicate-keys

Explained in JSON viewer (marks duplicate keys).

Emoji, accents and escapes

Every kind of escape, emoji written as surrogate pairs, accented names, right-to-left text, and a zero-width space that looks like nothing.

GET/api/test-json/unicode

Explained in JSON escape and unescape.

1,000 levels deep

An object nested 1,000 levels deep. Recursive parsers and printers can run out of stack long before they run out of memory.

GET/api/test-json/deep-nesting

Explained in JSON viewer.

A string at the top level

Valid JSON that isn’t an object or an array. Code that expects data.something gets undefined.

GET/api/test-json/top-level-string

Explained in What is JSON?.

An empty list

No results. Worth testing, because it’s easy to write code that assumes there’s always a first item.

GET/api/test-json/empty-array

Just null

The whole body is null. It’s valid JSON, and some APIs send it to mean “not found” while still using status 200.

GET/api/test-json/null

1 MB of cleaning runs

About 1 MB of valid JSON: thousands of records, for testing parsing speed, memory and how your UI copes with a long list.

GET/api/test-json/large-1mb

Explained in JSON viewer (opens files up to 20 MB).

4 MB of cleaning runs

About 4 MB of valid JSON. Big enough to notice in a browser tab or a slow parser.

GET/api/test-json/large-4mb

Explained in JSON viewer (opens files up to 20 MB).

Using them in tests

// Vitest or Jest: the app should cope when the API sends HTML
const res = await fetch("https://www.jsontidy.com/api/test-json/html-error-page");
await expect(res.json()).rejects.toThrow(SyntaxError);

# Python, with requests
import requests
r = requests.get("https://www.jsontidy.com/api/test-json/trailing-comma")
r.json()  # raises requests.exceptions.JSONDecodeError

Every response is the same each time, has an open CORS header and is cached, so the URLs work from browser code and CI alike. The address is https://www.jsontidy.com/api/test-json/ plus the name, like empty-body, and you can add .json to the end if a tool wants a file name.

For realistic data that does parse, with pagination, slow responses and error codes, use the fake JSON API. If you have a parse error and want to know why, paste it into the JSON error lookup.