JSON Key Naming Conventions: camelCase vs snake_case in APIs
5 min read
There is no official standard for JSON key naming. The JSON specification says keys are strings — it doesn't mandate a case convention. In practice, two conventions dominate: camelCase and snake_case.
What Major APIs Use
| API / Platform | Convention | Example |
|---|---|---|
| Google APIs | camelCase | {"userId": 1, "displayName": "Alice"} |
| Twitter/X API | snake_case | {"user_id": 1, "screen_name": "alice"} |
| GitHub API | snake_case | {"login": "alice", "avatar_url": "..."} |
| Stripe API | snake_case | {"customer_id": "cus_123", "created_at": 1234} |
| Firebase | camelCase | {"createdAt": "...", "userId": "abc"} |
| AWS APIs | PascalCase | {"InstanceId": "i-123", "State": "running"} |
The Case for camelCase
- Native to JavaScript — no conversion needed in frontend code
- Used by Google's JSON Style Guide
- Shorter than snake_case (no underscores)
- Natural fit for APIs consumed primarily by web/mobile clients
The Case for snake_case
- More readable — underscores create visual word boundaries
- Native to Python, Ruby, and SQL — no conversion needed in backend code
- Used by most of the largest APIs (GitHub, Twitter, Stripe)
- Consistent with database column names (which are almost always snake_case)
The Real Answer: Match Your Stack
The best convention depends on where the JSON is produced and consumed:
| Scenario | Recommended | Why |
|---|---|---|
| JavaScript backend + JavaScript frontend | camelCase | No conversion needed anywhere |
| Python/Ruby backend + any frontend | snake_case | Matches backend idioms; frontends can convert |
| Public API consumed by many languages | snake_case | More universally readable |
| Internal microservices | Either (just be consistent) | Internal consistency matters most |
Converting at the Boundary
In practice, many teams convert JSON keys at the API boundary. A Python backend returns snake_case, and a middleware or client-side utility converts to camelCase for the React frontend. Libraries like humps (JavaScript) and djangorestframework-camel-case (Python) automate this.
Rules for Good JSON Keys
- Be consistent. Don't mix
userIdanduser_namein the same response. - Use descriptive names.
createdAtbeatsca. - Avoid abbreviations.
organizationIdnotorgId. - Use plural for arrays.
itemsnotitemfor a list. - Avoid nesting deeper than 3 levels. Flatten when possible.
Convert JSON Keys Instantly
Use our JSON keys to camelCase or JSON keys to snake_case converter to transform API responses. For plain text, try the camelCase converter or the case converter hub.