Data Types
JSON supports exactly six data types:
| Type | Syntax | Example | Notes |
|---|
| String | Double-quoted text | "hello" | Must use double quotes, not single |
| Number | Integer or float | 42, 3.14, -1, 2.5e10 | No hex, octal, NaN, or Infinity |
| Boolean | true / false | true | Lowercase only — True is invalid |
| Null | null | null | Lowercase only — None, NULL invalid |
| Object | { } with key-value pairs | {"a": 1} | Keys must be double-quoted strings |
| Array | [ ] with ordered values | [1, "two", null] | Elements can be mixed types |
String Escape Sequences
These are the only valid escape sequences inside JSON strings:
| Sequence | Meaning | Example |
|---|
\\" | Double quote | "She said \\"hi\\"" |
\\\\ | Backslash | "C:\\\\Users\\\\file" |
\\/ | Forward slash | "date: 2025\\/03\\/10" |
\\b | Backspace | "back\\bspace" |
\\f | Form feed | "form\\ffeed" |
\\n | Newline | "line1\\nline2" |
\\r | Carriage return | "return\\rhere" |
\\t | Tab | "col1\\tcol2" |
\\uXXXX | Unicode character (4 hex digits) | "\\u00e9" → é |
Syntax Rules
| Rule | Valid ✓ | Invalid ✗ | Why |
|---|
| Keys must be double-quoted | {"name": "Jo"} | {name: "Jo"} | Unquoted keys are not allowed |
| Strings use double quotes only | "hello" | 'hello' | Single quotes are not valid JSON |
| No trailing commas | {"a": 1, "b": 2} | {"a": 1, "b": 2,} | Trailing commas cause parse errors |
| No comments | {"a": 1} | {"a": 1} // note | JSON has no comment syntax |
| No undefined | {"a": null} | {"a": undefined} | Use null instead |
| No hex numbers | 255 | 0xFF | Only decimal notation allowed |
| No leading zeros | 0.5 | 007 | Leading zeros are not valid |
| No NaN or Infinity | null | NaN, Infinity | Use null or a string representation |
Object Syntax
An object is an unordered set of key-value pairs wrapped in curly braces:
{
"name": "Alice",
"age": 30,
"active": true,
"address": {
"street": "123 Main St",
"city": "Portland"
},
"tags": ["admin", "user"]
}
| Rule | Detail |
|---|
| Delimiter | Curly braces { } |
| Key-value separator | Colon : |
| Pair separator | Comma , |
| Keys | Must be unique double-quoted strings |
| Values | Any valid JSON type |
| Empty object | {} is valid |
Array Syntax
An array is an ordered list of values wrapped in square brackets:
["apple", "banana", "cherry"]
[1, "mixed", true, null, {"nested": "ok"}, [1, 2]]
[]
| Rule | Detail |
|---|
| Delimiter | Square brackets [ ] |
| Element separator | Comma , |
| Element types | Any valid JSON type (can be mixed) |
| Ordering | Preserved — order matters |
| Empty array | [] is valid |
Nesting Rules
| What Can Be Nested | Example |
|---|
| Object inside object | {"user": {"name": "Jo"}} |
| Array inside object | {"ids": [1, 2, 3]} |
| Object inside array | [{"id": 1}, {"id": 2}] |
| Array inside array | [[1, 2], [3, 4]] |
There is no formal depth limit in the JSON spec, but most parsers cap recursion around 100–512 levels. Keep nesting shallow (3–4 levels) for readability.
Common Gotchas
| Mistake | Correct Version | Error You'll See |
|---|
{name: "Jo"} | {"name": "Jo"} | Unexpected token n |
{'name': 'Jo'} | {"name": "Jo"} | Unexpected token ' |
{"a": 1,} | {"a": 1} | Unexpected token } |
{"a": undefined} | {"a": null} | Unexpected token u |
{"a": NaN} | {"a": null} | Unexpected token N |
[1, 2, 3,] | [1, 2, 3] | Unexpected token ] |
{"a": 0xFF} | {"a": 255} | Unexpected token x |
| Unescaped newline in string | Use \\n instead | Unterminated string |
File Extension & MIME Type
| Property | Value |
|---|
| File extension | .json |
| MIME type | application/json |
| HTTP Content-Type header | Content-Type: application/json; charset=utf-8 |
| Default encoding | UTF-8 |
| RFC specification | RFC 8259 (supersedes RFC 7159, RFC 4627) |
| ECMA standard | ECMA-404 |
Validate your JSON instantly: Paste any JSON into our JSON Formatter to detect syntax errors, auto-fix trailing commas, and pretty-print with one click.