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 / PlatformConventionExample
Google APIscamelCase{"userId": 1, "displayName": "Alice"}
Twitter/X APIsnake_case{"user_id": 1, "screen_name": "alice"}
GitHub APIsnake_case{"login": "alice", "avatar_url": "..."}
Stripe APIsnake_case{"customer_id": "cus_123", "created_at": 1234}
FirebasecamelCase{"createdAt": "...", "userId": "abc"}
AWS APIsPascalCase{"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:

ScenarioRecommendedWhy
JavaScript backend + JavaScript frontendcamelCaseNo conversion needed anywhere
Python/Ruby backend + any frontendsnake_caseMatches backend idioms; frontends can convert
Public API consumed by many languagessnake_caseMore universally readable
Internal microservicesEither (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 userId and user_name in the same response.
  • Use descriptive names. createdAt beats ca.
  • Avoid abbreviations. organizationId not orgId.
  • Use plural for arrays. items not item for 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.