JSON Cheat Sheet
The rules of JSON on one page, plus what every common JSON.parse error actually means and how to fix it.
Cheat sheetPrintableFree, no login
Updated 28 October 2026
Format, validate and fix JSON — it points to the exact line and column of an error.
Open the JSON formatterData types
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Double quotes only. Single quotes are not JSON. |
| Number | 42 -3.14 1e6 | No leading zeros, no NaN or Infinity, no hex. |
| Boolean | true false | Lowercase only. |
| Null | null | Lowercase. There is no undefined. |
| Object | {"name": "Alice", "age": 30} | Keys must be double-quoted strings. |
| Array | [1, "two", true, null] | Values can be mixed types. |
Syntax rules
- Keys and strings use double quotes:
"key", never'key'orkey. - No trailing commas after the last item:
[1, 2], not[1, 2,]. - No comments.
//and/* */are not allowed (JSONC and JSON5 allow them). - The top level can be any value, but APIs almost always use an object or an array.
- Dates have no type of their own. Use an ISO 8601 string:
"2026-10-28T09:30:00Z". - Whole numbers above
9007199254740991(253 − 1) lose precision in JavaScript —9007199254740993parses as9007199254740992. Send big IDs as strings. - Duplicate keys are allowed by the grammar but behave differently between parsers (most keep the last one). Avoid them.
- Files should be UTF-8 and served as
Content-Type: application/json.
Escape sequences
| Escape | Means |
|---|---|
\" | Double quote |
\\ | Backslash |
\/ | Forward slash (optional) |
\n | New line |
\r | Carriage return |
\t | Tab |
\b \f | Backspace, form feed |
\u00e9 | Unicode character by code point (é) |
Raw tabs and line breaks inside a string are not allowed — they must be written as \t and \n. Windows paths need doubled backslashes: "C:\\Users\\alice".
Common JSON errors and how to fix them
| Error message (Chrome, Edge, Node.js) | Example | Cause | Fix | |
|---|---|---|---|---|
| Expected double-quoted property name | {"a": 1,} | A trailing comma after the last property, or a single-quoted key | Remove the comma; use double quotes | Try ↗ |
| Expected property name or '}' | {'a': 1} | Key in single quotes or without quotes | Write keys as "a" | Try ↗ |
| Unexpected token ']', "[1, 2,]" is not valid JSON | [1, 2,] | A trailing comma in an array | Remove the last comma | Try ↗ |
| Expected ',' or '}' after property value | {"a": 1 "b": 2} | A missing comma, or a // comment after a value | Add the comma; remove comments | Try ↗ |
| Expected ',' or ']' after array element | {"a": [1, 2 | Unclosed array or truncated JSON | Close every [ and { | Try ↗ |
| Unexpected end of JSON input | empty | Empty string, or the response was cut off | Check that the request returned a body | |
| "undefined" is not valid JSON | undefined | You parsed the JavaScript value undefined | Check the variable before JSON.parse | Try ↗ |
| Unexpected token '<', "<!DOCTYPE "... is not valid JSON | <!DOCTYPE html> | The server sent an HTML page (often a 404 or login page), not JSON | Check the URL and the response status | Try ↗ |
| Unexpected token 'N', … is not valid JSON | {"a": NaN} | NaN or Infinity, which JSON doesn't support | Use null or a string | Try ↗ |
| Bad control character in string literal | {"a": "line1
line2"} | A raw line break or tab inside a string | Escape it as \n or \t | Try ↗ |
| Bad escaped character | {"path": "C:\Users"} | A single backslash before a letter that isn't an escape | Double the backslash: \\ | Try ↗ |
| Unexpected non-whitespace character after JSON | {"a":1}{"b":2} | Two JSON documents, or extra text after the end | Wrap them in an array, or use JSON Lines | Try ↗ |
Firefox words these differently, for example JSON.parse: expected double-quoted property name at line 1 column 9. Try ↗ opens the broken example in the JSON formatter, which points to the line and column and can fix the common cases in one click.
Parse and write JSON in code
| Language | Parse | Write (pretty) |
|---|---|---|
| JavaScript | JSON.parse(text) | JSON.stringify(obj, null, 2) |
| Python | json.loads(text) | json.dumps(obj, indent=2) |
| Go | json.Unmarshal(data, &v) | json.MarshalIndent(v, "", " ") |
| Java (Jackson) | mapper.readValue(text, User.class) | mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj) |
| C# (.NET) | JsonSerializer.Deserialize<User>(text) | JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true }) |
| PHP | json_decode($text, true) | json_encode($v, JSON_PRETTY_PRINT) |
| Command line (jq) | jq '.users[0].name' file.json | jq . file.json (pretty), jq -c . file.json (minify) |
JSON vs JSONC vs JSON5 vs JSON Lines
| Format | What's different | Used for |
|---|---|---|
| JSON | The strict standard (RFC 8259) | APIs, data exchange |
| JSONC | JSON plus // and /* */ comments | tsconfig.json, VS Code settings |
| JSON5 | Comments, trailing commas, single quotes, unquoted keys, hex numbers | Hand-edited config files |
| JSON Lines (NDJSON) | One JSON value per line, no wrapping array | Logs, streaming, big data exports |
| JSON Schema | A JSON document that describes the shape of other JSON | Validation, API docs |
Frequently asked questions
Does JSON allow comments?
No. Standard JSON has no comments. Formats like JSONC (used by VS Code and tsconfig.json) and JSON5 add them, but a strict JSON parser such as
JSON.parse will reject them.Does JSON allow trailing commas?
No.
[1, 2,] and {"a": 1,} are invalid JSON. Remove the comma after the last item.Can JSON use single quotes?
No. Strings and keys must use double quotes. Single quotes are a JavaScript and Python habit, not JSON.
What does "Unexpected token < in JSON at position 0" mean?
Your code tried to parse an HTML page as JSON — usually a 404, 500 or login page returned by the server. Check the request URL and the response status. Newer Chrome words it as
Unexpected token '<', "<!DOCTYPE "... is not valid JSON.How do I store a date in JSON?
As a string in ISO 8601 format, for example
"2026-10-28T09:30:00Z". JSON has no date type.