← All Posts

How to Convert Text Between Cases (camelCase, snake_case, kebab-case)

Published on February 10, 2026

Why Naming Conventions Matter

Every programmer deals with naming — variables, functions, classes, files, database columns, API fields, CSS classes, and URLs all need names. The case convention you choose communicates intent, improves readability, and ensures consistency across a codebase. Using the wrong case convention is not just a style issue — it can cause bugs when systems are case-sensitive, break API contracts, or confuse team members reading your code.

Different programming languages, frameworks, and contexts have established conventions. Understanding these conventions and being able to convert between them quickly is a practical skill that saves time every day.

The Major Case Conventions Explained

camelCase

In camelCase, the first word is lowercase and each subsequent word starts with an uppercase letter. No separators are used. The name comes from the "humps" created by the uppercase letters, resembling a camel's back.

// camelCase examples
userName
firstName
getUserById
isAuthenticated
maxRetryCount
httpResponseCode
backgroundColor
onClick

Where it is used: JavaScript and TypeScript variables, functions, and object properties. Java local variables and method names. Swift and Kotlin variables. JSON property names in most APIs.

PascalCase

PascalCase (also called UpperCamelCase) is like camelCase but the first letter is also capitalized. Every word begins with an uppercase letter.

// PascalCase examples
UserProfile
HttpClient
DatabaseConnection
ShoppingCart
AuthProvider
ReactComponent
EventHandler
LinkedList

Where it is used: Class names in virtually every language. React component names (required by JSX). C# method names and public properties. TypeScript interfaces and type aliases. Enum names in many languages.

snake_case

In snake_case, all letters are lowercase and words are separated by underscores. It is highly readable because the underscores create clear visual boundaries between words.

# snake_case examples
user_name
first_name
get_user_by_id
is_authenticated
max_retry_count
http_response_code
created_at
updated_at

Where it is used: Python variables, functions, and module names (per PEP 8). Ruby variables and method names. Rust variables and function names. Database column and table names (SQL). PHP variables and functions. Elixir variables and function names.

kebab-case

kebab-case uses lowercase letters with hyphens separating words. The name comes from the words being "skewered" on a hyphen like food on a kebab stick. Note that hyphens are not valid in variable names in most programming languages, so kebab-case is primarily used outside of code.

/* kebab-case examples */
user-name
first-name
background-color
font-size
max-retry-count
my-component
data-user-id
content-type

Where it is used: CSS property names and class names. HTML attributes (including custom data-* attributes). URL slugs. npm package names. Lisp and Clojure function names. File names in many frontend projects. HTTP headers (e.g., content-type).

SCREAMING_SNAKE_CASE

SCREAMING_SNAKE_CASE (also called UPPER_SNAKE_CASE or CONSTANT_CASE) uses all uppercase letters with underscores between words. The all-caps format immediately signals that a value is a constant.

// SCREAMING_SNAKE_CASE examples
MAX_RETRY_COUNT
API_BASE_URL
DATABASE_URL
NODE_ENV
DEFAULT_TIMEOUT
HTTP_STATUS_OK
PI_VALUE
SECRET_KEY

Where it is used: Constants in most languages. Environment variables. Enum values in C, Java, and Rust. Preprocessor macros in C/C++. Global configuration values.

Language Conventions at a Glance

Each language has established conventions that most projects follow. Here is a quick reference:

Language     | Variables/Functions  | Classes/Types    | Constants
-------------|---------------------|------------------|-----------------
JavaScript   | camelCase           | PascalCase       | SCREAMING_SNAKE
TypeScript   | camelCase           | PascalCase       | SCREAMING_SNAKE
Python       | snake_case          | PascalCase       | SCREAMING_SNAKE
Ruby         | snake_case          | PascalCase       | SCREAMING_SNAKE
Rust         | snake_case          | PascalCase       | SCREAMING_SNAKE
Go           | camelCase           | PascalCase       | PascalCase
Java         | camelCase           | PascalCase       | SCREAMING_SNAKE
C#           | camelCase           | PascalCase       | PascalCase
PHP          | snake_case          | PascalCase       | SCREAMING_SNAKE
Swift        | camelCase           | PascalCase       | camelCase
Kotlin       | camelCase           | PascalCase       | SCREAMING_SNAKE
CSS          | kebab-case          | —                | —
HTML attrs   | kebab-case          | —                | —
SQL          | snake_case          | PascalCase       | SCREAMING_SNAKE
URLs/slugs   | kebab-case          | —                | —

Converting Cases with Code

Here is how to convert between cases programmatically. These implementations handle the most common scenarios:

JavaScript

// Split any case into words
function splitWords(str) {
  return str
    // Insert space before uppercase letters in camelCase/PascalCase
    .replace(/([a-z])([A-Z])/g, "$1 $2")
    // Replace separators with spaces
    .replace(/[_\-]+/g, " ")
    .trim()
    .toLowerCase()
    .split(/\s+/);
}

// camelCase
function toCamelCase(str) {
  const words = splitWords(str);
  return words[0] + words.slice(1)
    .map(w => w.charAt(0).toUpperCase() + w.slice(1))
    .join("");
}

// PascalCase
function toPascalCase(str) {
  return splitWords(str)
    .map(w => w.charAt(0).toUpperCase() + w.slice(1))
    .join("");
}

// snake_case
function toSnakeCase(str) {
  return splitWords(str).join("_");
}

// kebab-case
function toKebabCase(str) {
  return splitWords(str).join("-");
}

// SCREAMING_SNAKE_CASE
function toScreamingSnake(str) {
  return splitWords(str).join("_").toUpperCase();
}

// Examples
console.log(toCamelCase("user_first_name"));     // "userFirstName"
console.log(toSnakeCase("getUserById"));          // "get_user_by_id"
console.log(toKebabCase("BackgroundColor"));      // "background-color"
console.log(toScreamingSnake("maxRetryCount"));   // "MAX_RETRY_COUNT"
console.log(toPascalCase("my-component-name"));   // "MyComponentName"

Python

import re

def split_words(s: str) -> list[str]:
    """Split any case convention into a list of lowercase words."""
    # Insert space before uppercase in camelCase/PascalCase
    s = re.sub(r"([a-z])([A-Z])", r"\1 \2", s)
    # Replace separators with spaces
    s = re.sub(r"[_\-]+", " ", s)
    return s.lower().split()

def to_camel_case(s: str) -> str:
    words = split_words(s)
    return words[0] + "".join(w.capitalize() for w in words[1:])

def to_pascal_case(s: str) -> str:
    return "".join(w.capitalize() for w in split_words(s))

def to_snake_case(s: str) -> str:
    return "_".join(split_words(s))

def to_kebab_case(s: str) -> str:
    return "-".join(split_words(s))

def to_screaming_snake(s: str) -> str:
    return "_".join(split_words(s)).upper()

# Examples
print(to_snake_case("getUserById"))        # "get_user_by_id"
print(to_camel_case("background_color"))   # "backgroundColor"
print(to_kebab_case("MyComponentName"))    # "my-component-name"

API Naming: Choosing the Right Convention

When designing APIs, the casing of your field names has a real impact on developer experience. Different ecosystems have different expectations:

  • REST APIs with JSON — camelCase is the most common convention because JavaScript (the primary JSON consumer) uses camelCase. Google, GitHub, Stripe, and Twitter all use camelCase in their JSON responses.
  • REST APIs consumed by Python/Ruby — Some teams prefer snake_case because it matches the conventions of those languages. The trade-off is that JavaScript consumers must convert the keys.
  • GraphQL — camelCase is the standard convention for field names, matching the JavaScript ecosystem where GraphQL originated.
  • Database columns — snake_case is dominant in SQL databases. ORMs like Prisma, SQLAlchemy, and ActiveRecord automatically convert between snake_case (database) and the language's convention (application).
  • URL paths — kebab-case is the standard for URL slugs and path segments. Search engines treat hyphens as word separators, making kebab-case URLs better for SEO.
// API response in camelCase (most common)
{
  "userId": 42,
  "firstName": "Alice",
  "lastName": "Johnson",
  "emailAddress": "alice@example.com",
  "createdAt": "2026-02-10T12:00:00Z",
  "isVerified": true
}

// Same data in snake_case (Python/Ruby convention)
{
  "user_id": 42,
  "first_name": "Alice",
  "last_name": "Johnson",
  "email_address": "alice@example.com",
  "created_at": "2026-02-10T12:00:00Z",
  "is_verified": true
}

The most important rule is consistency. Pick one convention for your API and stick with it across all endpoints. Mixing conventions within a single API is confusing and error-prone. If you need to support multiple conventions, consider a serialization layer that converts field names automatically.

Practical Tips

  • Use your linter. ESLint's camelcase rule, Pylint's naming-convention checks, and Rubocop's naming rules all enforce consistency automatically.
  • Configure your ORM. Most ORMs can automatically convert between database snake_case and application camelCase. In Prisma, this is the @map directive. In SQLAlchemy, use column_property.
  • Handle acronyms carefully. "HTTP response code" in camelCase should be httpResponseCode, not hTTPResponseCode. Most style guides treat acronyms as regular words when they appear in camelCase.
  • Be consistent with file names. Frontend projects typically use kebab-case for files (user-profile.tsx) while matching PascalCase for the component inside (UserProfile).
  • Use a converter tool. When migrating data between systems with different conventions or renaming a batch of variables, a dedicated Case Converter saves significant time.

Need to extract data from websites?

PulpMiner turns any webpage into structured JSON data. No scraping code needed — just point, click, and get clean data.

Try PulpMiner Free

No credit card required