Batch Text Case Conversion
Convert thousands of strings between camelCase, snake_case, kebab-case, UPPER_CASE, and Title Case using CLI tools, Python, and Node.js scripts.
The Problem
You're renaming database columns from camelCase to snake_case, converting API response keys for a different language convention, or normalizing CSV headers across dozens of files. Doing it string by string is slow and error-prone.
Why Batch Processing Matters
Batch case conversion is essential for database schema migrations (camelCase → snake_case), API response normalization between systems with different conventions, i18n string key standardization, code refactoring (renaming variables across files), and CSV header normalization before data import.
Common Use Cases
- Convert database column names from camelCase to snake_case during migration
- Normalize API response keys between camelCase (JavaScript) and snake_case (Python)
- Standardize CSV headers across multiple files from different sources
- Convert constant names to SCREAMING_SNAKE_CASE across a codebase
- Transform kebab-case CSS class names to camelCase for JS object keys
Step-by-Step Instructions
Identify source and target case formats
Common formats: camelCase, PascalCase, snake_case, kebab-case, SCREAMING_SNAKE_CASE, Title Case. Use the Text Case Converter to test a few examples.
Prepare your input
Extract the strings to convert: CSV column headers, JSON keys, variable names from code. Put them in a text file (one per line) or identify the column/key to transform in your data files.
Run the conversion script
Choose from the scripts below based on your language preference. Each handles edge cases like acronyms (HTMLParser → html_parser), numbers (value2key → value_2_key), and consecutive capitals.
Review and spot-check
Acronyms and abbreviations are the most common source of unexpected results. Check that HTTPSProxy converts to https_proxy (not h_t_t_p_s_proxy). Adjust the regex if needed.
Code Examples
# camelCase → snake_case (handles consecutive caps correctly)
echo "myVariableName" | sed -r 's/([A-Z])/_\L\1/g' | sed 's/^_//'
# Output: my_variable_name
# snake_case → camelCase
echo "my_variable_name" | sed -r 's/_([a-z])/\U\1/g'
# Output: myVariableName
# Batch: convert all strings in a file (one per line)
while read line; do
echo "$line" | sed -r 's/([A-Z])/_\L\1/g' | sed 's/^_//'
done < input.txt > output.txt
# Convert CSV headers (first line only)
head -1 data.csv | tr ',' '\n' | \
sed -r 's/([A-Z])/_\L\1/g' | sed 's/^_//' | \
paste -sd',' > /tmp/header.csv
tail -n+2 data.csv >> /tmp/header.csv
mv /tmp/header.csv data_snake.csv
Single vs Batch Comparison
Type 'myVariableName' → select snake_case → get 'my_variable_name'
$ wc -l api_fields.txt 156 api_fields.txt $ python batch_case.py firstName → first_name lastName → last_name emailAddress → email_address phoneNumber → phone_number createdAt → created_at ... Converted 156 field names to snake_case $ python convert_csv_headers.py Converted 24 column headers to snake_case
Frequently Asked Questions
How do I handle acronyms like HTML, API, or UUID in case conversion?
The Python/Node.js scripts above handle consecutive capitals correctly: HTMLParser → html_parser, getAPIKey → get_api_key. The key is the two-step regex: first split between consecutive caps and a lowercase letter, then between lowercase and uppercase.
Can I convert JSON keys recursively (nested objects)?
Yes — wrap the conversion in a recursive function: if the value is an object, recurse into it; if it's an array, map each element. In Python: def convert_keys(obj): return {to_snake(k): convert_keys(v) for k, v in obj.items()} with base cases for non-dict types.
What about converting variable names in source code files?
For code refactoring, use your IDE's rename feature (safer) or sed with word boundaries: sed -i 's/\bmyVar\b/my_var/g' *.py. Be careful with string literals and comments. Consider using tools like rope (Python) or jscodeshift (JavaScript) for AST-aware renaming.
Related Batch Guides
Try these tools interactively
Each tool runs in your browser with no signup required. Process single items instantly.