JSON (JavaScript Object Notation) is a lightweight text format for data interchange. It is human-readable and language-independent. JSON has exactly 6 data types and strict syntax rules — no comments, no trailing commas, only double-quoted strings.
| Item | Syntax / Value | Description |
|---|---|---|
| string | "Hello, World!" | Double-quoted UTF-8 string — no single quotes, no unquoted |
| number | 42 / 3.14 / -7 / 1.5e10 | Integer or float — no Infinity, no NaN, no hex |
| boolean | true / false | Lowercase only — not True or False |
| null | null | Null value — lowercase only |
| object | {"key": value, "key2": value2} | Unordered key-value pairs — keys MUST be strings |
| array | [value1, value2, value3] | Ordered list of values of any type |
| nesting | objects and arrays can nest infinitely | Deep nesting is valid but impacts performance |
| no trailing comma | {"a":1,"b":2} ← correct | Trailing commas are NOT valid JSON |
| no comments | // and /* */ are NOT valid JSON | JSON has no comment syntax |
| no undefined | undefined is NOT a valid JSON value | undefined is JavaScript-only |
| no functions | Functions are NOT valid JSON values | JSON is data only — no code |
| no NaN/Infinity | NaN and Infinity are NOT valid JSON | Use null instead |
| Whitespace | Whitespace (spaces, newlines) is ignored | JSON is whitespace-insensitive (outside strings) |
| Unicode | All Unicode characters are valid in strings | \uXXXX escape for control chars |
| Escape sequences | \" \\ \/ \b \f \n \r \t \uXXXX | Valid JSON string escape sequences |
| Root element | Any JSON value can be the root | Not just objects — arrays, strings, numbers are valid root |
| Content-Type | application/json | HTTP Content-Type header for JSON |
| File extension | .json | Standard file extension |
| BOM | JSON MUST NOT have a byte order mark (BOM) | UTF-8 without BOM is the standard |
| Max size | No defined limit — but large files impact performance | Practical limit depends on parser/memory |
{
"_comment_note": "JSON has no comments — use this key trick for docs only",
"student": {
"id": 1001,
"name": "Alice Smith",
"email": "alice@mywebuniversity.com",
"active": true,
"gpa": 3.95,
"graduation": null,
"enrolled": "2024-09-01T08:00:00Z",
"scores": [95, 87, 92, 98, 88],
"address": {
"street": "123 Learn Ave",
"city": "Techville",
"state": "CA",
"zip": "90210",
"country": "US"
},
"courses": [
{ "id": "CS101", "name": "Python", "credits": 3, "grade": "A" },
{ "id": "CS201", "name": "JavaScript", "credits": 3, "grade": "A-" },
{ "id": "CS301", "name": "Data Science", "credits": 4, "grade": "A+" }
],
"tags": ["scholarship", "dean-list", "remote"],
"metadata": {
"created": "2024-08-15",
"updated": "2026-06-25",
"version": 3
}
}
}
/* Valid JSON types at root level: */
// Object: { "key": "value" }
// Array: [1, 2, 3]
// String: "hello"
// Number: 42
// Boolean: true
// Null: null