CamelCase to Snake Case Converter (Live Code & JSON Key Formatter)

Convert JavaScript camelCase and PascalCase identifiers into clean, PEP 8 and SQL-compliant snake_case. Easily format lists of variables, database columns, and JSON payloads with smart acronym handling.

0 lines
standard_snake

The Acronym Edge Case: Why Naive Regex Fails

Most basic online case converters use a naive regular expression:

// Flawed naive regex used by basic converters:
str.replace(/([A-Z])/g, "_$1").toLowerCase();

When applied to common production variables containing acronyms (such as parseHTTPRequest or getUserID), this naive approach breaks the identifier:

  • Naive Converter Output: parse_h_t_t_p_request or get_user_i_d (Broken syntax)
  • Urban Mixo Smart Converter: parse_http_request or get_user_id (Production ready)

Our algorithm uses lookahead expressions (/([A-Z]+)([A-Z][a-z])/g) to distinguish between consecutive capital letters in an acronym and the start of a subsequent word.

Naming Conventions Across Languages & Frameworks

Language / Framework Standard Convention Example Syntax Official Style Guide
Python snake_case user_profile_id PEP 8 Specification
PostgreSQL & MySQL snake_case created_at, order_total SQL Standard (Case-Insensitive)
Rust snake_case fn calculate_total() Rust API Guidelines
JavaScript & TypeScript camelCase userProfileId ECMAScript Standard
C / C++ / Python Constants SCREAMING_SNAKE_CASE MAX_BUFFER_SIZE Global Constant Definition

When to Convert CamelCase to Snake_Case

  1. Serializing REST API Payloads: Frontend applications running TypeScript commonly use camelCase (e.g., userId). Backend endpoints in Python (FastAPI/Django) or Ruby on Rails expect snake_case (e.g., user_id).
  2. Mapping ORM Schemas to Relational Databases: Relational databases like PostgreSQL treat unquoted column names as lowercase. Converting entity models (like createdAt to created_at) prevents quoting errors in raw SQL queries.
  3. Generating Environment Variables: Use the UPPERCASE toggle to convert configuration keys into SCREAMING_SNAKE_CASE for .env files or Docker runtime configurations.

Frequently Asked Questions

What is the difference between camelCase and snake_case?

In camelCase, words are joined without spaces and each word after the first begins with an uppercase letter (e.g., userProfileData). In snake_case, all letters are lowercase and words are separated by underscores (e.g., user_profile_data).

Does this converter support PascalCase?

Yes. PascalCase (where the first letter is capitalized, like UserProfile) converts cleanly into standard user_profile without generating leading underscores.

What is SCREAMING_SNAKE_CASE used for?

SCREAMING_SNAKE_CASE (all-caps with underscores) is the industry standard for declaring constants, global configuration settings, and environment variables across Python, C/C++, Java, and Docker.