JSON Cheat Sheet
Everything on one page: syntax rules, the six types, escaping, and the errors that catch everyone. Print it (Cmd/Ctrl+P) - it is styled for paper too.
The five rules of JSON
- A document is one value: an object, array, string, number, boolean, or null.
- Double quotes only - for every key and every string. No single quotes, no unquoted keys.
- No trailing commas after the last item of an object or array.
- No comments - neither // nor /* */.
- Whitespace between tokens is ignored; key order carries no meaning; array order does.
The six data types
| Type | Example | Notes |
|---|---|---|
| string | "hello é \n" | Double quotes; unicode escapes allowed |
| number | 42, -3.14, 1.2e10 | No NaN, Infinity, leading zeros, or hex |
| boolean | true, false | Lowercase only |
| null | null | Lowercase only; not None/nil/undefined |
| object | {"key": "value"} | Unordered; keys should be unique |
| array | [1, "two", null] | Ordered; mixed types allowed |
Not JSON types: dates (use ISO 8601 strings), undefined, functions, comments, NaN, Infinity.
String escaping
| Write | Meaning | Required? |
|---|---|---|
| \" | double quote | Yes |
| \\ | backslash | Yes |
| \n | newline | Yes (raw newline in a string is invalid) |
| \t | tab | Yes |
| \r | carriage return | Yes |
| \b, \f | backspace, form feed | Yes |
| \uXXXX | unicode code point (\u00e9 = e-acute) | Optional for non-ASCII |
| \/ | forward slash | Never required (allowed) |
Need it done for you? Use the JSON Escape tool.
Valid vs invalid at a glance
| Invalid | Valid | Rule |
|---|---|---|
| {'a': 1} | {"a": 1} | Double quotes for keys and strings |
| {a: 1} | {"a": 1} | Keys must be quoted |
| {"a": 1,} | {"a": 1} | No trailing commas |
| {"a": 1 // port} | {"a": 1} | No comments |
| {"n": NaN} | {"n": null} | No NaN/Infinity |
| {"d": 2026-07-30} | {"d": "2026-07-30"} | Dates are strings |
| {"z": 007} | {"z": 7} | No leading zeros |
| {"s": "a b"} | {"s": "a\n b"} | Escape raw newlines |
Common errors, decoded
| Error message | Almost always means |
|---|---|
| Unexpected token < in JSON at position 0 | You received HTML, not JSON (error page, wrong URL) |
| Unexpected end of JSON input | Empty string or truncated document |
| "[object Object]" is not valid JSON | You parsed an object that was already parsed |
| Expecting value: line 1 column 1 (char 0) | Python: empty/non-JSON input or a BOM |
| Expecting property name enclosed in double quotes | Single-quoted or unquoted keys, or a trailing comma |
| Converting circular structure to JSON | The object references itself - JSON cannot represent cycles |
All 26 error guides with per-language fixes: JSON error hub.
Parse & serialize one-liners
| Language | Parse | Serialize (pretty) |
|---|---|---|
| JavaScript | JSON.parse(text) | JSON.stringify(obj, null, 2) |
| Python | json.loads(text) | json.dumps(obj, indent=2) |
| Go | json.Unmarshal(b, &v) | json.MarshalIndent(v, "", " ") |
| Java (Jackson) | mapper.readValue(s, T.class) | writerWithDefaultPrettyPrinter() |
| C# | JsonSerializer.Deserialize<T>(s) | JsonSerializer.Serialize(v, opts) |
| PHP | json_decode($s, true) | json_encode($v, JSON_PRETTY_PRINT) |
| Ruby | JSON.parse(s) | JSON.pretty_generate(v) |
| Rust | serde_json::from_str(&s)? | serde_json::to_string_pretty(&v)? |
Test anything from this page in the JSON Formatter - or try to beat the spot-the-error quiz.
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →
JSON QuizSpot the invalid JSON - 10 rounds.JSON FormatterFormat and validate with code, tree, table, and graph views.JSON EscapePaste any text and get a valid JSON string literalJSON Error Guides26 exact error messages decoded, with fixes.JSON ComparePaste two JSON documents and see only real differencesJSON to CSVPaste a JSON array of objects on the left and get a spreadsheet-ready CSV with headers on the rightJWT DecoderPaste a JWT and instantly see its decoded header and payload with expiry statusMock JSON GeneratorPaste one sample record and generate up to 1,000 mock records with the same structureJSON to TypeScriptPaste an API response and get TypeScript interfaces