Convert text to snake_case

Type userAccountId to get user_account_id, live as you type. snake_case is the convention for Python, Ruby, Rust, SQL columns and many REST payloads. A lowercase letter or digit followed by an uppercase letter marks a split. All-caps runs such as APIKey do not split without a space. Conversion stays in this tab.

camelCase

userAccountId

PascalCase

UserAccountId

snake_case

user_account_id

kebab-case

user-account-id

CONSTANT_CASE

USER_ACCOUNT_ID

Converted as you typeNothing leaves this tab

Runs in this tab · nothing is uploaded · Verify in 10 seconds →

What this does

snake_case lowercases everything and joins words with underscores, detecting camelCase humps on the way in: userAccountId becomes user_account_id, and spaces and hyphens become underscores too. Type below and read the snake_case row, the CONSTANT_CASE row gives you the all-caps variant for free.

The conversion is driven by one regular expression boundary: a lowercase letter or digit followed by an uppercase letter ([a-z0-9] then [A-Z]) marks a word split, which is why userAccountId gains exactly two underscores. On the 244 unique keys in our sample corpus, 67 are multi-word, snake_case makes each of those boundaries cost one visible character, averaging 7.5 characters per key versus camelCase's 7.2.

Where snake_case is the convention

snake_case is the identifier style of languages that treat the underscore as cheap and the capital letter as reserved for types. The all-caps variant, SCREAMING_SNAKE, is the same string with every letter raised and is how constants and environment variables are spelled on this page’s CONSTANT_CASE row.

  • Python (PEP 8). Function names, variables, arguments and module-level names are snake_case: get_user_by_id, account_id, default_timeout. Classes are CapWords (PascalCase): HttpRequest, not http_request. Constants are SCREAMING_SNAKE: MAX_RETRIES, DEFAULT_TIMEOUT. PEP 8’s other rules (line length, imports) are out of scope for a case converter.
  • Ruby and Rust. Both use snake_case for methods, functions, modules and variables (find_by, to_string) and PascalCase for types (ActiveRecord, HashMap). Rust traits and Ruby classes share that capital-first rule. Ruby constants are SCREAMING_SNAKE.
  • SQL and databases. Column and table names are snake_case in almost every house style (created_at, user_id). PostgreSQL folds unquoted identifiers to lowercase, so userAccountId and useraccountid are the same name unless you quote them; the underscore is the only word boundary that survives. MySQL and SQLite are case-insensitive on most deployments for the same reason.
  • Environment variables and REST. POSIX-style process environments use SCREAMING_SNAKE (DATABASE_URL, NODE_ENV, AWS_REGION). Rails, Django, Laravel and FastAPI JSON often uses snake_case keys. Browser JavaScript and GraphQL usually do not: convert at the edge instead of shipping mixed payloads.
  • Not snake_case. JavaScript, Java, Kotlin, C# and Swift members are camelCase; their types are PascalCase. Go exports PascalCase and keeps unexported names in camelCase, never underscores. CSS, HTML attributes, URL slugs and CLI flags are kebab-case. Search engines treat an underscore in a path as a joiner, not a break.

How snake_case splits identifiers

Three steps, in order: insert an underscore wherever an ASCII lowercase letter or digit is immediately followed by an uppercase letter; replace every run of hyphens or whitespace with a single underscore; lowercase the whole string. Existing underscores are left alone. That is why userAccountId and getUserID become user_account_id and get_user_id, and why parseJSON becomes parse_json (the eJ pair matches) while HTTPRequest does not split at all.

Digits attach to the word they already sit in unless an uppercase letter follows: utf8String becomes utf8_string, html5Parser becomes html5_parser, user2fa stays user2fa, user2Fa becomes user2_fa. v2APIClient becomes v2_apiclient: only the 2A pair matches, so API stays one chunk.

Unicode letters are not treated as [a-z0-9], so a capital after a non-ASCII letter is not a split: caféMenu becomes cafémenu. A capital after an ASCII letter still is: naïveParser becomes naïve_parser. Diacritics are kept and then run through JavaScript’s toLowerCase (NAÏVE_PARSER becomes naïve_parser). Dots and other punctuation stay (user.accountId becomes user.account_id). Consecutive hyphens collapse (user--account becomes user_account) but consecutive underscores do not (user__account stays user__account). Leading or trailing spaces become leading or trailing underscores. CONSTANT_CASE is this same snake_case string, uppercased.

In data work the same spelling shows up as pandas column labels, Django model fields, SQLAlchemy attribute names, Alembic revision labels and Airflow task ids. Leave Python dunder names (__init__, __tablename__) alone: they are already snake_case and the leading underscores are meaningful. A Flyway or Rails migration filename that starts with a timestamp should stay a filename, not be pasted here as if it were a single identifier. Ruff, pylint and RuboCop all flag camelCase names in those languages; they expect the underscore form this row emits.

Worth typing: createdAt becomes created_at, handleClick becomes handle_click, getObjectOr404 becomes get_object_or_404, useEffect becomes use_effect. XMLHttpRequest becomes xmlhttp_request because only the pR pair matches. HTTPRequest, APIKey and IOError still collapse to a single lowercase word.

When it goes wrong

All-caps acronym runs do not split: APIKey becomes apikey, HTTPRequest becomes httprequest, IOError becomes ioerror and JSONParser becomes jsonparser, because there is no lowercase-or-digit-then-uppercase boundary to cut on. Write “API key”, “HTTP request” or parseJSON (e then J) when you need the underscore. If SQL is the destination and the converted name collides with a reserved word (order, user, group are classics), quote it or prefix it rather than trusting case conventions to save you.

When to use this

Use snake_case when the destination is Python, Ruby, Rust, a SQL column, an environment variable (then read the CONSTANT_CASE row) or a Rails/Django-style JSON field. Use the camelCase row when the same name has to become a JavaScript property.

This page is a focused view of theCase Converter, which has the full set of options.

Frequently asked questions

What is SCREAMING_SNAKE_CASE for?

The all-caps variant (CONSTANT_CASE row in this tool) marks constants and environment variables: MAX_RETRIES, DATABASE_URL, NODE_ENV. PEP 8, Ruby and most deployment platforms use that spelling. It is snake_case run through toUpperCase, not a separate parser.

Why snake_case for SQL columns?

SQL identifiers are case-insensitive by default in most databases (PostgreSQL folds unquoted names to lowercase), so word separation by capitals is lost. Underscores survive. created_at stays readable; createdAt becomes createdat once it is stored unquoted.

Does this follow PEP 8?

For names, yes: functions and variables in snake_case, constants in SCREAMING_SNAKE on the CONSTANT_CASE row. Classes are PascalCase, so use that row, not this one. PEP 8 also covers line length, imports and whitespace, which a case converter cannot help with.

Why did APIKey become apikey, not api_key?

The splitter only fires on a lowercase letter or digit followed by an uppercase letter. APIKey, HTTPRequest and IOError have no such pair, so they lowercase as a single word. Paste “API key”, api_key or parseJSON (which does contain eJ) when you need the underscore.

Should a JSON API use snake_case or camelCase?

Follow the consumer. Browser JavaScript and GraphQL expect camelCase keys; Python and Ruby backends often emit snake_case. Pick one spelling per payload and convert at the boundary. Mixing both in one document is what this page is for undoing.