Follow these conventions to write clean, maintainable JSON that works well across teams and tools.
| Style | Example | Recommendation |
|---|---|---|
| snake_case | "first_name" | Recommended for most JSON (Python-friendly) |
| camelCase | "firstName" | Common in JavaScript ecosystems |
| kebab-case | "first-name" | Avoid — hyphens conflict with arithmetic |
| PascalCase | "FirstName" | Avoid — reserved for classes in some languages |
Rule of thumb: Choose one style and use it consistently across your entire project.
Keep it flat when possible. Prefer:
// Good — flat
{
"street": "123 Main St",
"city": "Boston",
"zip": "02101"
}
// Over-engineered — avoid unnecessary nesting
{
"address": {
"street": "123 Main St",
"city": "Boston",
"zip": "02101"
}
}
| Tip | Good | Bad |
|---|---|---|
| Use booleans | "active": true | "active": "yes" |
| Use numbers for numbers | "count": 5 | "count": "5" |
| Use null for missing | "middle": null | "middle": "null" or omit |
| Arrays for lists | "tags": ["a","b"] | "tags": "a,b" |
| Use ISO dates | "2026-07-03" | "07/03/2026" |
users.json, products.json).json extension — never .txt or custom extensions| Pitfall | Why it's bad | Solution |
|---|---|---|
| Comments in JSON | Not part of the spec — breaks parsers | Use a separate schema or docs file |
| Trailing commas | Invalid in JSON | Remove comma after last item |
| Overly deep nesting | Hard to read and access | Flatten or use references |
| Inconsistent key naming | Confusing for developers | Adopt a naming convention and stick to it |
| Storing binary data | JSON is text-only | Use Base64 encoding or store separately |
{
// ✔ Do this
"name": "Alice",
"age": 30,
"active": true,
"tags": ["json", "guide"],
"address": null,
// ✘ Not this
"name": 'Alice', // single quotes
"age": "30", // number as string
"active": "true", // boolean as string
"tags": "json,guide", // array as string
"address": "null" // null as string
}
Remember: Valid JSON is strict JSON. A single error makes the entire file unusable. Always validate your JSON files before using them.