π‘ A complete JSON reference in table format: structure, data types, syntax rules, validation, and real-world applications.
| Category | Subcategory | Description | Example |
|---|---|---|---|
| Basics | JSON Definition | Lightweight format for data-interchange, easy to read and write. | { "key": "value" } |
| Structure | Built on key-value pairs (objects) and ordered lists (arrays). | { "name": "John", "age": 30 } |
|
| MIME Type | MIME type for JSON is application/json. |
- | |
| Data Types | String | Text enclosed in double quotes. | "name": "John" |
| Number | Can be integer or floating-point. | "age": 30 or "weight": 70.5 |
|
| Boolean | Supports true and false. |
"isStudent": true |
|
| Null | Represents absence of value. | "middleName": null |
|
| Object | Key-value collection, wrapped in {}. |
{ "name": "John", "age": 30 } |
|
| Array | Ordered list of values inside []. |
"hobbies": ["reading", "coding"] |
|
| Syntax Rules | Double Quotes | Keys and string values must use double quotes. | "name": "John" |
| Key-Value Pair Separator | Colon : separates keys from values. |
"age": 30 |
|
| Comma Separation | Items separated with commas. | { "name": "John", "age": 30 } |
|
| No Trailing Comma | Last item must not end with a comma. | β
Correct: { "key": "val" } β Incorrect: { "key": "val", } |
|
| White Spaces | Whitespace is allowed and ignored. | { "name" : "John" , "age" : 30 } |
|
| Advanced Structures | Nested Objects | JSON objects inside other objects. | { "user": { "name": "John" } } |
| Nested Arrays | Arrays within arrays. | "matrix": [[1, 2], [3, 4]] |
|
| Arrays of Objects | Array holding multiple object entries. | [{"id": 1}, {"id": 2}] |
|
| Mixed Types in Arrays | JSON array can mix data types. | [1, "text", true, null] |
|
| Encoding | Unicode | JSON supports UTF-8 and Unicode. | "symbol": "\u03C0" |
| Operations | Parsing | Convert JSON string to native object. | JSON.parse('{"a":1}') |
| Stringifying | Convert object to JSON string. | JSON.stringify({a:1}) |
|
| Accessing Data | Use dot/bracket notation. | obj.name or obj["name"] |
|
| Modifying Data | Reassign value via property. | obj.name = "Doe" |
|
| Removing Data | Delete property from object. | delete obj.name |
|
| Security | JSON Injection | Sanitize inputs to prevent injection attacks. | - |
| Escape Characters | Escape special characters like newline (\n), tab (\t). |
"message": "Line1\nLine2" |
|
| Validation | JSON Validators | Use tools like JSONLint for validation. | - |
| JSON Schema | Enforce structure and rules using schemas. | See: json-schema.org | |
| Best Practices | No Comments | JSON does not support comments. | β // Not allowed in JSON |
| Consistent Keys | Use camelCase or snake_case consistently. |
"firstName": "Alice" |
|
| Minified vs Pretty | Minify for storage, prettify for readability. | JSON.stringify(obj, null, 2) |
|
| Common Issues | Trailing Comma | Will break parsers. | Avoid: { "key": "val", } |
| Improper Quotes | Use double quotes ", not single '. |
β
"key" β 'key' |
|
| Invalid Values | NaN, Infinity, and undefined are invalid. |
- | |
| Libraries | JavaScript | JSON.parse(), JSON.stringify() |
- |
| Python | json.loads(), json.dumps() |
import json |
|
| Other Languages | Use Gson (Java), Newtonsoft.Json (.NET), fastjson (Go), etc. |
- | |
| APIs & Integration | REST APIs | JSON is commonly used for request/response payloads. | Content-Type: application/json |
| Headers | Set header to let server know you're sending/expecting JSON. | Accept: application/json |
|
| Debugging | Browser Tools | Use DevTools β Network tab β Preview/Response. | Chrome, Firefox |
| Online Formatters | Tools like jsonformatter.org | - | |
| Advanced | JSON Web Token (JWT) | Secure token format with Base64-encoded JSON parts. | header.payload.signature |
| JSONP | For legacy cross-domain requests using script tags. | callback({ "data": "ok" }) |
|
| Protobuf (vs JSON) | JSON is human-readable; protobuf is faster and compact (used in gRPC). | - |
π Quick Tip: Always validate your JSON before using it in your app to avoid hidden bugs! Use https://jsonlint.com or browser dev tools.
π Suggested Learning:
π¬ "Bookmark this cheatsheet for daily JSON work. Clean, concise, and built to be your JSON best friend!"
π The most comprehensive JSON Cheatsheet youβll ever need. Perfect for devs, API lovers, and anyone who deals with structured data.