JSON Syntax Cheatsheet
A quick reference for JSON syntax — value types, object and array rules, string escapes, and the most common validation mistakes.
Try the JSON FormatterSections
Value Types
| Type | Example | Notes |
|---|---|---|
String | "hello world" | Must use double quotes. Single quotes are invalid. |
Number | 42 3.14 -7 1.5e10 | Integer or float. No NaN, Infinity, or hex literals. |
Boolean | true false | Lowercase only. True / False are invalid. |
Null | null | Lowercase only. |
Object | {"key": "value"} | Keys must be double-quoted strings. |
Array | [1, "two", false, null] | Ordered list of any value types. |
Object Rules
| Rule | Valid | Invalid |
|---|---|---|
Keys must be strings | {"name": "Jane"} | {name: 'Jane'} |
Keys must use double quotes | {"key": 1} | {'key': 1} |
No trailing comma | {"a": 1, "b": 2} | {"a": 1, "b": 2,} |
No comments | {"rate": 0.5} | {"rate": 0.5 /* tax */} |
Duplicate keys — avoid | {"id": 1} | {"id": 1, "id": 2} (undefined behavior) |
Array Rules
| Rule | Valid | Invalid |
|---|---|---|
No trailing comma | [1, 2, 3] | [1, 2, 3,] |
Mixed types allowed | [1, "two", null, true] | — (all fine in JSON) |
Nested arrays OK | [[1, 2], [3, 4]] | — (no restriction) |
String Escape Sequences
| Sequence | Character |
|---|---|
\" | Double quote |
\\ | Backslash |
\/ | Forward slash (optional) |
\b | Backspace |
\f | Form feed |
\n | Newline |
\r | Carriage return |
\t | Tab |
\uXXXX | Unicode code point (4 hex digits) |
Common Validation Errors
| Error | Bad Example | Fix |
|---|---|---|
Trailing comma | {"a": 1,} | {"a": 1} |
Single-quoted key | {'a': 1} | {"a": 1} |
Unquoted key | {a: 1} | {"a": 1} |
Comment | {"x": 1 // comment} | {"x": 1} |
undefined value | {"x": undefined} | {"x": null} |
NaN / Infinity | {"x": NaN} | {"x": null} or use a number |
Unescaped newline | {"s": "line1 line2"} | {"s": "line1\nline2"} |