JSON: what the format is, syntax rules, examples and common errors
Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →
JSON is a text format for exchanging data between programs. Every programming language reads it, so most APIs answer in it, settings are stored in it and logs are written in it. The format is simple: objects in curly braces, arrays in square brackets and six value types. Below are the rules, an example and the errors people hit most.
What JSON consists of
An object is a set of key: value pairs in curly braces; the key is always a string in double quotes. An array is an ordered list of values in square brackets. A value is a string, a number, true or false, null, another object or an array. Nesting is unlimited, which suits an order with items or a customer with addresses.
What JSON does not have
JSON has no comments, single quotes, unquoted keys or trailing commas. There is no date type: dates travel as strings, usually ISO 8601. Integers and decimals are not distinguished, and NaN and Infinity are forbidden. All of this is allowed in a JavaScript object, which causes most errors.

Valid JSON is not yet a correct response
A syntax check only says the text can be parsed. It will not tell you the total is wrong, the status is not in the list or an internal field leaked. That takes content checks: a schema, field rules and calculations.
A JSON example
{
"id": 5001,
"status": "PAID",
"createdAt": "2026-11-09T10:15:00Z",
"customer": { "id": 7, "name": "Анна Петрова", "phone": null },
"items": [
{ "productId": 101, "name": "Мышь", "quantity": 2, "price": 1290.0 },
{ "productId": 102, "name": "Кабель", "quantity": 1, "price": 590.0 }
],
"subtotal": 3170.0,
"discount": 300.0,
"total": 2870.0,
"gift": false
}This is an order object: numbers have no quotes, strings use double quotes, a missing phone is null, and items are an array of objects. Indentation and line breaks are optional and only help people.

Value types
| Type | Example | Watch out for |
|---|---|---|
| String | "PAID" | Double quotes only; escape quotes and backslashes: \" and \\ |
| Number | 42, -3.14, 1e6 | No quotes or leading zeros; NaN and Infinity are forbidden |
| Boolean | true, false | Lowercase only |
| Null | null | Not the same as an empty string or a missing field |
| Object | {"id": 7} | Keys are double-quoted strings |
| Array | [1, 2, 3] | Order matters, types may differ |
JSON, JavaScript object, XML and YAML
| JSON | JavaScript object | XML | YAML | |
|---|---|---|---|---|
| Comments | No | Yes | Yes | Yes |
| Quoted keys | Required, double | Optional | Tags instead of keys | Optional |
| Trailing comma | Error | Allowed | n/a | n/a |
| Data types | Six types | Plus functions, dates, undefined | All text, schema sets types | Like JSON plus dates |
| Where used | APIs, logs, settings | Code | SOAP, documents | Settings, CI |
Common JSON errors
| Error | What it looks like | More |
|---|---|---|
| Trailing comma | {"a": 1,} | Unexpected token |
| Single quotes or unquoted key | {'a': 1} or {a: 1} | Unexpected token |
| An HTML page instead of JSON | <!DOCTYPE html>… | DOCTYPE is not valid JSON |
| Truncated or empty response | {"items": [ | Unexpected end of JSON input |
| Generic parse failure | JSON parse error | JSON parse error |
| A long number lost precision | 12345678901234567890 → …67000 | JSON formatter |
What happens when a key repeats
The JSON standard does not forbid repeating a key in one object, so every library chooses which value to keep. On 25 November 2026 we ran one response through five parsers:
{"orderId":5002,"status":"PAID","amount":2970,"status":"CANCELLED"}| Parser | Result |
|---|---|
| Python, json.loads | status = CANCELLED |
| Node.js, JSON.parse | status = CANCELLED |
| Java, Jackson 2.17 default | status = CANCELLED |
| Java, Jackson with STRICT_DUPLICATE_DETECTION | error Duplicate field 'status' |
| Java, org.json 20231013 | error Duplicate key "status" |
Two Java services reading this response disagree: one sees a cancelled order, the other throws, and nobody sees PAID. A schema check still passes. Only the raw text or a strict parser catches the repeat: object_pairs_hook in Python, STRICT_DUPLICATE_DETECTION in Jackson. This response is order 5002 in the practice API.
Tools to read and check JSON
- Validate syntax: finds the line and character of the error.
- Format: pretty-prints or minifies.
- Open as a tree: shows structure and the field path.
- Compare two JSON documents: shows changed fields.
- Extract values with JSONPath: selects fields from a large response.
- Validate against JSON Schema: checks the response against a contract.
- Convert to CSV: opens an export in Excel.
All tools run in the browser and send nothing to a server.
All guides in the JSON section
- JSON parse error: what it means and how to fix it
- Unexpected token is not valid JSON: what it means and how to find it
- Unexpected end of JSON input: why the JSON ends early
- Unexpected token <, <!DOCTYPE is not valid JSON: the server returned HTML
- Online JSON validator that explains the error
- Format JSON online: pretty print, minify and sort keys
- Open and view JSON online: tree view and field paths
- Compare two JSON documents online: added, missing and changed
- JSON to CSV online: a spreadsheet without uploading the file
- JSONPath online: test an expression on your JSON
- Validate JSON against a JSON Schema online
- Validate required and unexpected JSON fields
- Validate every element of a JSON array
- Decode a JWT online: expiry, payload and signature
Frequently asked questions
What is JSON?
A text format for exchanging data: objects in curly braces, arrays in square brackets, values are strings, numbers, true, false and null.
What data types does JSON have?
Six: string, number, boolean, null, object and array. Dates travel as strings.
Can JSON have comments?
No. JSON5 and JSONC allow them, but a standard parser fails.
JSON vs a JavaScript object?
JSON needs double-quoted keys and has no single quotes, comments, functions or trailing commas.
Repeat this on your own API
Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.
Download FreeDownload and first runNo sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.
References
Start with the linked example and compare its result with your own test requirement.