TFT

Convert TOML to Environment Variables

Generate environment variable declarations from your TOML config. This tool creates .env or shell script output, perfect for Docker, cloud deployments, and CI/CD pipelines.

TOML to ENV Converter

How the TOML to ENV Converter Works

This tool converts TOML configuration files into environment variable format (.env). Paste your TOML content and get flat KEY=value pairs suitable for .env files, Docker environment configs, or deployment systems.

The converter flattens TOML's hierarchical structure into dot-notation or underscore-separated keys. A TOML table [database] with key "host" becomes DATABASE_HOST or database.host in env format. Nested structures are flattened appropriately.

Output follows .env conventions: KEY=value pairs, one per line. Values are quoted when necessary. Comments from TOML are preserved. Copy into your .env file or use for deployment environment configuration.

When You'd Actually Use This

Deploying to cloud platforms

Heroku, Vercel, and other platforms use environment variables. Convert your TOML config to env format for deployment. Map each setting to an env var.

Creating Docker environment files

Docker uses .env files for container environment. Convert TOML configs to env format for docker-compose. Consistent config across environments.

Migrating from TOML to env vars

Moving to 12-factor app methodology? Convert file-based TOML configs to environment variables. Better for cloud-native deployments.

Setting up CI/CD pipelines

CI systems use environment variables for secrets and config. Convert TOML to env format for GitHub Actions, GitLab CI, or Jenkins pipelines.

Creating staging/production configs

Maintain one TOML structure, convert to environment-specific .env files. staging.env, production.env with different values, same structure.

Building configuration scripts

Shell scripts often source .env files. Convert TOML to env format, source in scripts. Consistent config between apps and deployment scripts.

What to Know Before Using

Environment variables are flat.TOML's hierarchy becomes flat keys. [db.connection] host becomes DB_CONNECTION_HOST. Deep nesting creates long key names.

Naming conventions vary.UPPERCASE_WITH_UNDERSCORES is standard for env vars. The converter can use this or preserve original case. Match your application's expectations.

All values become strings.Environment variables are strings. "42" and "true" are strings, not numbers/booleans. Your app must parse types from strings.

Special characters need quoting.Values with spaces, quotes, or special chars need proper escaping. The converter handles this. Shell sourcing requires careful escaping.

Security note: Environment variables can leak in logs and error messages. Don't store sensitive secrets in .env files that might be committed or logged.

Common Questions

How are nested tables converted?

Nested tables become prefixed keys: [database.connection] host → DATABASE_CONNECTION_HOST. The full path becomes the environment variable name.

What about arrays in TOML?

Arrays become comma-separated values: key=item1,item2,item3. Or indexed: KEY_0=a, KEY_1=b. Choose based on how your app parses arrays.

Can I convert back from env to TOML?

This tool does TOML to env. For env to TOML, parse the flat keys and reconstruct hierarchy. Tools exist for bidirectional conversion.

How do I load .env files?

Node.js: dotenv package. Python: python-dotenv. Rust: dotenv crate. Most languages have libraries to load .env into environment variables.

Should I commit .env files to git?

No, never commit .env files with secrets. Add .env to .gitignore. Commit .env.example with placeholder values. Each developer creates their own .env.

What about boolean and number types?

All env vars are strings. Your code must parse: process.env.PORT → parseInt(), process.env.DEBUG → === 'true'. Type info is lost in conversion.

How do I handle multiline values?

.env files support multiline with quotes or escapes. For complex multiline, consider base64 encoding or using a different config approach.