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.
/api/test-json/empty-bodyExplained 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.
/api/test-json/html-error-pageExplained 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.
/api/test-json/server-error-htmlExplained 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.
/api/test-json/truncatedExplained 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.
/api/test-json/trailing-commaExplained in Trailing commas in JSON.
Single quotes and unquoted keys
JavaScript object syntax instead of JSON: keys without quotes and strings in single quotes.
/api/test-json/single-quotesExplained 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.
/api/test-json/python-reprExplained 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.
/api/test-json/nanExplained in JSON error lookup.
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.
/api/test-json/two-documentsExplained 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.
/api/test-json/control-characterExplained 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.
/api/test-json/bomExplained 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.
/api/test-json/wrong-content-typeValid, 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.
/api/test-json/big-numbersExplained in JSON viewer (shows numbers exactly).
The same key twice
The JSON spec allows it, but most parsers quietly keep only the last value.
/api/test-json/duplicate-keysExplained 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.
/api/test-json/unicodeExplained 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.
/api/test-json/deep-nestingExplained 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.
/api/test-json/top-level-stringExplained 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.
/api/test-json/empty-arrayJust null
The whole body is null. It’s valid JSON, and some APIs send it to mean “not found” while still using status 200.
/api/test-json/null1 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.
/api/test-json/large-1mbExplained 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.
/api/test-json/large-4mbExplained 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.JSONDecodeErrorEvery 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.
Comments
A config file with // and /* */ comments. Fine for tsconfig.json and VS Code, an error for JSON.parse.
/api/test-json/commentsExplained in JSONC to JSON.