Python example
Convert snake_case to camelCase in Python
Split a predictable snake_case string into underscore-separated tokens, keep the first token lowercase, and capitalize the remaining tokens before joining them.
Python code
def snake_to_camel(value: str) -> str:
parts = [part for part in value.strip("_").split("_") if part]
if not parts:
return ""
head, *tail = parts
return head.lower() + "".join(part[:1].upper() + part[1:].lower() for part in tail)
print(snake_to_camel("user_profile_image"))
# userProfileImageThe helper removes leading/trailing underscores and empty tokens caused by repeated underscores, producing deterministic output for ordinary snake_case.
Python itself commonly uses snake_case, so this is most useful at JSON, API, generated-client, or JavaScript integration boundaries.
Edge cases to consider
- Acronym output depends on the consuming system's convention.
- Nested dictionaries need recursive key conversion, not a string helper alone.
- Values with capitals, dashes, or spaces need broader tokenization.
- Prefer conversion at serialization boundaries when the external API contract is fixed.
Example
| Before | After |
|---|---|
| user_profile_image | userProfileImage |
| __user__profile__ | userProfile |
| api_response_url | apiResponseUrl |
| created_at | createdAt |
Python code
cases = {
"user_profile_image": "userProfileImage",
"__user__profile__": "userProfile",
"api_response_url": "apiResponseUrl",
"created_at": "createdAt",
}
for value, expected in cases.items():
assert snake_to_camel(value) == expectedTry the conversion online
Use the browser-based converter for quick checks, batch values, acronym handling, or inputs that mix several naming conventions.
Detected: snake_case
camelCase output
userProfileImageUrl
All naming formats
camelCase
userProfileImageUrlPascalCase
UserProfileImageUrlsnake_case
user_profile_image_urlkebab-case
user-profile-image-urlCONSTANT_CASE
USER_PROFILE_IMAGE_URLdot.case
user.profile.image.urlpath/case
user/profile/image/urlConversion happens locally in your browser. Your input is not sent to a conversion server.