snake_case Converter
Convert text into snake_case for database columns, file names and code.
What gets turned into an underscore
Spaces, tabs, line breaks and hyphens all become word boundaries, and so does the point inside a camelCase or PascalCase name where a small letter meets a capital. Every word is then made lowercase and the words are joined with a single underscore. Runs of separators collapse, and any at the start or end are dropped, so you never get __ or a leading underscore.
| Input | snake_case |
|---|---|
| First Name | first_name |
| getUserById | get_user_by_id |
| CreatedAt | created_at |
| get-user-by-id | get_user_by_id |
| Customer E-mail Address | customer_e_mail_address |
| price_USD | price_usd |
Note the hyphen in E-mail: it is a separator like any other, so e and mail end up as two words.
Converting spreadsheet headers to column names
The usual job is turning headers like Order Date or Customer E-mail Address into database column or dataframe names. Paste the headers one at a time. If you paste a column of headers, the line breaks are treated as separators and the whole list becomes one name: first name and last name on two lines give first_name_last_name.
A faster route for many headers is to put them on one line separated by a character the tool keeps, such as a comma, convert them together, and split the result back apart. Order Date,Ship Date gives order_date,ship_date.
Characters that survive the conversion
Only separators are replaced. Brackets, symbols, apostrophes and dots stay in the output, and most of them aren't valid in an unquoted SQL column or a Python variable:
order total ($)givesorder_total_($)Is Active?givesis_active?user.emailstaysuser.email
A name that starts with a digit is also a problem in both SQL and Python. 10 Tips for SEO becomes 10_tips_for_seo, which needs quoting in SQL and is a syntax error as a Python name. Strip punctuation from the headers first, and add a word in front of leading numbers, such as tip_10.
Mixed capitals and accented letters
Splitting at capitals only works for the unaccented letters A to Z, and only where a lowercase letter comes first:
iPhone casegivesi_phone_case, which is probably not what you want.XMLHttpRequestgivesxmlhttp_request, because a run of capitals is read as part of the next word.caféMenugivescafémenu, because the é before the M isn't recognised as a lowercase letter.
Accented letters themselves are kept, so Über Cool Größe becomes über_cool_größe. Many databases accept that only when the name is quoted, so for column names it is safer to replace accented letters first.
Frequently asked questions
What is SCREAMING_SNAKE_CASE?+
It is snake_case in capitals, as in MAX_RETRY_COUNT, and is the common style for constants and environment variables. This tool always produces lowercase, so convert the result to uppercase afterwards if you need it.
Should database columns use snake_case?+
It is a common choice because many databases fold unquoted names to one case, which makes camelCase names awkward to query, while snake_case reads the same either way. Follow whatever convention your project already uses.
Does it keep numbers?+
Yes. A number separated by spaces becomes its own segment, so page 2 title gives page_2_title. A number joined to a word stays attached, so version2Beta gives version2beta, since a digit next to a capital is not a split point.
Embed this tool on your website
Free to use on blogs, school sites and intranets. Paste this code into your page's HTML; please keep the credit line.
<iframe src="https://utilityapp.lat/embed/text/snake-case-converter" title="snake_case Converter" width="100%" height="600" style="border:0;max-width:760px" loading="lazy"></iframe> <p style="font-size:13px"><a href="https://utilityapp.lat/text/snake-case-converter">snake_case Converter</a> by UtilityApp</p>