JSON keys can be camelCase or snake_case, because the JSON standard has no naming rule at all. Use camelCase when your main consumers are JavaScript or TypeScript apps, use snake_case when your stack and your clients already speak it, and never mix the two in one API. Consistency matters far more than which style you pick.
What the JSON spec says about camelCase and snake_case keys
The JSON spec does not prefer camelCase or snake_case keys. Section 4 of RFC 8259 says only that "A name is a string" and that names within an object should be unique.
So "userId", "user_id", "UserID" and even "user id" are all valid keys. The quotes are required (why JSON requires double quotes explains that rule). What goes inside them is your call.
What published API guidelines recommend
Most written API style guides pick camelCase. The JSON:API recommendations say member names should be camel-cased, wordWordWord. The Azure REST API guidelines are blunter: "DO use camel case for all JSON field names."
Big public APIs went the other way. GitHub's REST API for repositories returns keys like full_name, html_url and default_branch, so snake_case clearly works at scale.
The case for camelCase keys
camelCase keys fit JavaScript, where most JSON ends up being read. A browser client can use the parsed object directly:
const user = await res.json();
console.log(user.firstName); // matches JS naming, no conversion
With snake_case, that same client writes user.first_name next to its own camelCase variables, or adds a conversion step.
It also sits closer to Java, C# and Go field names, so those serializers need less setup.
The case for snake_case keys
snake_case keys fit Python and Ruby backends, where variables and dictionary keys are already snake_case. A Python service that returns {"first_name": ...} needs no aliases at all.
Acronyms are easier too. Compare user_api_key_id with userApiKeyId, or try settling userID versus userId. In snake_case every word is lower case, so the question never comes up.
How to choose: a quick decision table
The right casing for JSON keys depends on who reads the JSON most.
| Your situation | Pick | Why |
|---|---|---|
| Public API, mostly web and mobile clients | camelCase | Matches JavaScript and most published guidelines |
| Internal API, Python or Ruby on both ends | snake_case | No conversion anywhere |
| Existing API with one style already | Keep it | A second style is worse than either |
| Config files read by one tool | That tool's style | Users copy examples from its docs |
| Data exported from a database | Column names as-is | Renaming adds a mapping step to keep in sync |
Convert at the boundary, not everywhere
The cleanest setup keeps each language's own style in its code and converts keys once, in the serializer.
Java with Jackson. One setting switches every key. PropertyNamingStrategies.SNAKE_CASE writes words in lower case separated by underscores, so a firstName field becomes first_name:
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
Python with Pydantic. An alias generator creates an alias for every field in a model. Pydantic ships to_camel, to_pascal and to_snake:
from pydantic import BaseModel, ConfigDict
from pydantic.alias_generators import to_camel
class User(BaseModel):
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
first_name: str
User(first_name="Ana").model_dump(by_alias=True) # {'firstName': 'Ana'}
JavaScript, consuming a snake_case API. A small mapper converts the keys after parsing:
const toCamel = (s) => s.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
const camelKeys = (obj) =>
Object.fromEntries(Object.entries(obj).map(([k, v]) => [toCamel(k), v]));
It only touches the top level. Nested objects and arrays need a recursive version. Leave keys that hold data, like user IDs used as keys, alone.
Mistakes that cause real bugs
The worst casing problem is mixing styles in one payload. A typical case: an endpoint returns created_at while its sibling returns updatedAt. A client reads data.createdAt, gets undefined, and shows a blank date. No error. JSON doesn't care, and JavaScript treats a missing key as normal.
Three more that bite:
- Inconsistent acronyms.
userIdin one place anduserIDin another are two different keys. - Renaming in a minor release. Changing
user_idtouserIdbreaks every client that reads the old key. - Converting data keys. A blanket converter that also rewrites map keys like
"en_US"corrupts your data.
To spot mixed casing, paste a response into the JSON viewer and scan the key names in the tree. Key order doesn't matter to parsers either; see JSON key order.
My recommendation
Use camelCase for any new public JSON API, and convert at the serializer if your backend is snake_case. It matches the guidelines and the most common client, and the serializer setting is one line.
That advice stops at existing APIs. If yours already ships snake_case, switching breaks every client for a cosmetic gain. Keep it and document it. Related: JSON vs JavaScript object, and for Python, converting a JSON string to an object.
FAQ
Does the JSON standard require camelCase?
No. RFC 8259 only says a name is a string and that names within an object should be unique. Any casing convention is a choice your API makes.
Which is more common in JSON APIs, camelCase or snake_case?
Both are widely used. Published guidelines such as the JSON:API recommendations and the Azure REST API guidelines call for camelCase, while some large APIs, such as GitHub's REST API, return snake_case keys.
Can I use snake_case in Python but camelCase in my JSON?
Yes. Pydantic can generate camelCase aliases for every field with an alias generator such as to_camel, so your Python code keeps snake_case names.
How do I make Jackson output snake_case keys?
Set the naming strategy to PropertyNamingStrategies.SNAKE_CASE on the ObjectMapper. Your Java fields stay camelCase and the JSON uses lower-case words separated by underscores.
Is it bad to mix camelCase and snake_case in one API?
Yes. Mixed casing forces every client to remember which field uses which style, and it causes silent bugs when a key is spelled the wrong way and simply reads as missing.