String Case Converter Guide — camelCase, snake_case, PascalCase, kebab-case & More
Which case format should you use for a variable name, a function, a CSS class, a database column, or an environment variable? Each language and framework has conventions — and violating them leads to style violations, linting errors, and code that looks wrong to every reviewer. This guide covers every case format, when to use each, and how to convert between them without doing it by hand.
All String Case Formats Explained
There are more naming conventions than most developers realize. Here is a complete reference covering all 10 major formats, what they look like, when to use them, and which languages and frameworks expect them.
| Format | Example | When to use | Languages / Frameworks |
|---|---|---|---|
| camelCase | getUserProfile | Variables, functions, JSON keys | JavaScript, TypeScript, Java, Swift |
| PascalCase | GetUserProfile | Classes, React components, interfaces | C#, TypeScript, React, .NET |
| snake_case | get_user_profile | Functions, vars, DB columns | Python, Ruby, PostgreSQL, Go |
| kebab-case | get-user-profile | CSS classes, URLs, HTML attributes | CSS, HTML, URL slugs, CLI flags |
| SCREAMING_SNAKE | GET_USER_PROFILE | Constants, environment variables | All languages, .env files, shell |
| dot.case | get.user.profile | Config keys, package names | Java packages, Spring config, .properties |
| path/case | get/user/profile | File paths, URL routes | REST API paths, file systems |
| COBOL-CASE | GET-USER-PROFILE | COBOL identifiers, legacy HTTP headers | COBOL, legacy enterprise systems |
| flatcase | getuserprofile | Database IDs, legacy systems | Legacy databases, some URL patterns |
| Sentence case | Get user profile | Error messages, UI labels | UI text, documentation, error strings |
Convert any string to all 10 formats instantly
camelCase vs snake_case — When to Use Which
The most common confusion is between camelCase and snake_case. Both are used for variable and function names — but in different languages and contexts. Mixing them in the same codebase causes linting errors and violates community conventions.
JavaScript & TypeScript → camelCase
getUserProfile, fetchOrderById, updatePaymentMethod. Variables, functions, and JSON keys all use camelCase in JS/TS. Class names use PascalCase.
Python & Ruby → snake_case
get_user_profile, fetch_order_by_id, update_payment_method. PEP 8 mandates snake_case for all functions and variables in Python. Class names use PascalCase.
CSS & HTML → kebab-case
user-profile-card, primary-button, nav-link. CSS properties and custom class names all use kebab-case. HTML data attributes use data-user-id format.
Constants & Env Vars → SCREAMING_SNAKE
MAX_RETRY_COUNT, DATABASE_URL, API_KEY. Constants in all languages and environment variables in .env files universally use SCREAMING_SNAKE_CASE.
Python function named in camelCase vs correct snake_case
PEP 8 violation
# Wrong: camelCase in Python violates PEP 8
def getUserProfile(userId):
return db.query(userId)
class userProfileManager: # Also wrong — should be PascalCase
def getUserById(self, id):
passCorrect Python convention
# Correct: snake_case for functions, PascalCase for classes
def get_user_profile(user_id):
return db.query(user_id)
class UserProfileManager: # PascalCase for class name
def get_user_by_id(self, user_id):
passHow to Convert camelCase to snake_case (Online & In Code)
camelCase to snake_case is the most common case conversion — needed when moving data between a JavaScript frontend and a Python backend, when renaming database columns to match Python conventions, or when generating SQL from ORM models.
// Simple regex: insert underscore before each uppercase letter, then lowercase all
function camelToSnake(str) {
return str
.replace(/([A-Z])/g, '_$1')
.toLowerCase();
}
camelToSnake('getUserProfile'); // → 'get_user_profile'
camelToSnake('updatePaymentMethod'); // → 'update_payment_method'
camelToSnake('parseHTTPSResponse'); // → 'parse_h_t_t_p_s_response'
// ↑ Acronyms need special handling — use a library for production code
// Better: handle consecutive capitals (acronyms)
function camelToSnakeAdvanced(str) {
return str
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
.replace(/([a-zd])([A-Z])/g, '$1_$2')
.toLowerCase();
}
camelToSnakeAdvanced('parseHTTPSResponse'); // → 'parse_https_response'import re
def camel_to_snake(name):
# Handle consecutive capitals (acronyms like HTTPS)
s1 = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\1_\2', name)
return re.sub(r'([a-zd])([A-Z])', r'\1_\2', s1).lower()
camel_to_snake('getUserProfile') # → 'get_user_profile'
camel_to_snake('parseHTTPSResponse') # → 'parse_https_response'
camel_to_snake('updatePaymentMethod') # → 'update_payment_method'
# Simpler version (no acronym handling):
simple = re.sub(r'([A-Z])', r'_\1', 'getUserProfile').lstrip('_').lower()
# → 'get_user_profile'Convert all 12 formats at once
How to Convert snake_case to camelCase
snake_case to camelCase is needed when consuming a Python or database API response in JavaScript — JSON keys come in snake_case but your frontend code expects camelCase.
// Convert snake_case to camelCase
function snakeToCamel(str) {
return str.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
}
snakeToCamel('get_user_profile'); // → 'getUserProfile'
snakeToCamel('update_payment_method'); // → 'updatePaymentMethod'
// Convert all keys in a JSON object from snake_case to camelCase (deep)
function keysToCamel(obj) {
if (Array.isArray(obj)) return obj.map(keysToCamel);
if (obj !== null && typeof obj === 'object') {
return Object.fromEntries(
Object.entries(obj).map(([k, v]) => [snakeToCamel(k), keysToCamel(v)])
);
}
return obj;
}
// Usage: convert entire API response
const camelResponse = keysToCamel(apiResponse);import re
def snake_to_camel(name):
components = name.split('_')
return components[0] + ''.join(x.title() for x in components[1:])
snake_to_camel('get_user_profile') # → 'getUserProfile'
snake_to_camel('update_payment_method') # → 'updatePaymentMethod'
# Using regex
def snake_to_camel_re(name):
return re.sub(r'_([a-z])', lambda m: m.group(1).upper(), name)
snake_to_camel_re('get_user_profile') # → 'getUserProfile'Library recommendation
For production JavaScript code, use the camelcase-keys npm package to convert all keys in an API response object from snake_case to camelCase recursively: import camelcaseKeys from 'camelcase-keys'; const data = camelcaseKeys(apiResponse, { deep: true });
Bulk Case Conversion — Convert Many Variable Names at Once
When migrating a codebase, renaming database columns, or generating config from a spreadsheet, you need to convert dozens or hundreds of names at once. The String Utilities Bulk Mode handles this in one operation with CSV export.
Copy a column from your spreadsheet
Select a column of variable names, column names, or identifiers in Excel or Google Sheets and copy it. The values will be newline-separated.
Paste into String Utilities Bulk Mode
Go to unblockdevs.com/string-utilities and paste your list. The tool auto-detects newline separators.
Review the conversion table
The table shows every name converted to all 12 case formats simultaneously — camelCase, snake_case, PascalCase, kebab-case, SCREAMING_SNAKE, and more.
Download as CSV
Click "Download CSV" to export the full table. Import it back into your spreadsheet as a reference sheet for the migration.
// Input (paste as newline-separated list):
getUserProfile
getOrderHistory
updatePaymentMethod
deleteUserAccount
sendEmailNotification
// CSV output from String Utilities:
// original | camelCase | snake_case | PascalCase | kebab-case
// getUserProfile | getUserProfile | get_user_profile | GetUserProfile | get-user-profile
// getOrderHistory | getOrderHistory | get_order_history | GetOrderHistory | get-order-history
// updatePaymentMethod| updatePaymentMethod | update_payment_method | UpdatePaymentMethod | update-payment-method
// deleteUserAccount | deleteUserAccount | delete_user_account | DeleteUserAccount | delete-user-account
// sendEmailNotification| sendEmailNotification | send_email_notification | SendEmailNotification | send-email-notificationReal-World Examples: When Case Matters
Case format is not just a style preference — using the wrong format in the wrong context causes real bugs. Here are three real-world scenarios where case conversion is required.
Scenario 1: Migrating DB columns to Python ORM
Your existing MySQL database has columns named userId, createdAt, paymentMethodId — camelCase from a legacy JS ORM. You are migrating to SQLAlchemy (Python), which expects snake_case column names: user_id, created_at, payment_method_id. Export the column list, bulk convert to snake_case in String Utilities, download CSV, and use it to write the migration script.
Scenario 2: Converting JSON API keys for JavaScript frontend
Your Python FastAPI backend returns JSON with snake_case keys: user_id, first_name, created_at. Your React frontend expects camelCase: userId, firstName, createdAt. Use the camelcase-keys library in your API client layer to convert all keys automatically on fetch.
Scenario 3: Generating CSS class names from component names
Your React component names are in PascalCase: UserProfileCard, PrimaryButton, NavMenuItem. CSS class names for BEM or Tailwind utilities should be kebab-case: user-profile-card, primary-button, nav-menu-item. Convert component names to kebab-case using String Utilities bulk mode to generate the class name reference.