Why a JSON Style Guide Matters
JSON has no opinion on key names, ordering, or formatting. Without team conventions, you end up with:
1{2 "user_name": "Alice",3 "userEmail": "[email protected]",4 "Phone": "+1-555-0100",5 "isActive": true,6 "is_admin": false,7 "created": "2026-04-02",8 "updated_at": 1711929600,9 "DOB": null10}Three different naming conventions. Two different date formats. Inconsistent null handling. This guide fixes all of it.
1. Naming Conventions
| Convention | Example | Used By |
|---|---|---|
| camelCase | "userName", "createdAt" | JavaScript, TypeScript, Google JSON Style Guide |
| snake_case | "user_name", "created_at" | Python, Ruby, PostgreSQL, Stripe API |
| kebab-case | "user-name", "created-at" | CSS, HTML attributes (rare in JSON) |
| PascalCase | "UserName", "CreatedAt" | C#, .NET APIs |
Important
Key Naming Rules
- ✓Use descriptive names:
"emailAddress"not"ea" - ✓Use plural for arrays:
"users"not"user" - ✓Use
is/hasprefix for booleans:"isActive","hasPermission" - ✓Use
Atsuffix for timestamps:"createdAt","updatedAt" - ✗Don't use abbreviations:
"cnt"→"count" - ✗Don't use type prefixes:
"strName"→"name"
2. Formatting & Indentation
| Context | Recommendation |
|---|---|
| Config files (package.json, tsconfig.json) | 2-space indentation — matches ecosystem convention |
| API responses (production) | Minified — no whitespace (smaller payload, faster transfer) |
| API responses (development / debug) | 2-space indented for readability |
| Documentation examples | 2 or 4-space — match your team standard |
| Logs and debugging | Pretty-printed with JSON.stringify(data, null, 2) |
1// Pretty-print for debugging2const pretty = JSON.stringify(data, null, 2);34// Minified for production5const minified = JSON.stringify(data);67// Custom formatting with a replacer8const filtered = JSON.stringify(data, ['id', 'name', 'email'], 2);3. Key Ordering
JSON objects are unordered by specification, but consistent ordering improves readability and diffing:
1{2 "id": "usr_8742",3 "type": "user",4 "name": "Alice Chen",5 "email": "[email protected]",6 "role": "admin",7 "isActive": true,8 "organizationId": "org_001",9 "permissions": ["read", "write", "delete"],10 "createdAt": "2026-01-15T10:30:00Z",11 "updatedAt": "2026-04-02T14:00:00Z"12}Tip
4. Date & Time Formats
| Format | Example | When to Use |
|---|---|---|
| ISO 8601 with timezone | "2026-04-02T14:30:00Z" | Timestamps in APIs (recommended default) |
| ISO 8601 date only | "2026-04-02" | Dates without time (birthdays, deadlines) |
| ISO 8601 with offset | "2026-04-02T14:30:00+05:30" | When local timezone matters |
| Unix timestamp (seconds) | 1711929600 | Machine-to-machine, avoid in user-facing APIs |
| Unix timestamp (ms) | 1711929600000 | JavaScript Date.now() compatible |
Important
At suffix: "createdAt", "expiresAt".5. Null, Empty, and Missing Values
| Scenario | Convention | Example |
|---|---|---|
| Field has no value | Use null — field is present but empty | "middleName": null |
| Field is inapplicable | Omit the key entirely | (key not present in response) |
| Empty collection | Use empty array, not null | "tags": [] |
| Empty text | Use empty string or null (document which) | "bio": "" or "bio": null |
| Unknown boolean | Use null, not false | "isVerified": null |
1{2 "id": "usr_8742",3 "name": "Alice Chen",4 "middleName": null,5 "bio": "",6 "tags": [],7 "avatarUrl": null,8 "isVerified": true,9 "deletedAt": null10}6. Enumerations and Constants
1{2 "status": "active",3 "role": "admin",4 "priority": "high",5 "currency": "USD"6}78// NOT this:9{10 "status": 1,11 "role": 0,12 "priority": 3,13 "currency": 84014}Tip
"status": "active" is immediately clear. "status": 1 requires a lookup table. Define valid values in your JSON Schema or API docs.7. Versioning JSON APIs
1{2 "apiVersion": "2",3 "data": {4 "id": "usr_8742",5 "name": "Alice Chen"6 },7 "meta": {8 "requestId": "req_abc123",9 "timestamp": "2026-04-02T14:30:00Z"10 }11}Common versioning strategies: URL path (/v2/users), header (Accept: application/vnd.api+json;version=2), or response envelope ("apiVersion": "2").
8. The Definitive Checklist
- ✓One naming convention across all endpoints (camelCase or snake_case)
- ✓ISO 8601 for all dates and timestamps
- ✓Consistent null vs omit strategy, documented
- ✓String enums instead of magic numbers
- ✓Plural names for arrays,
is/hasprefix for booleans - ✓Logical key ordering: identity → primary → data → relations → metadata
- ✓2-space indentation for config files, minified for production APIs
- ✓JSON Schema definition for every API endpoint
- ✓Linting in CI/CD (eslint-plugin-jsonc or custom rules)
Try It — Clean Up Inconsistent JSON
Try It Yourself
This JSON mixes conventions — try rewriting it with consistent camelCase