YAML to ENV
Flatten YAML into .env format, with custom separators for nested keys.
YAML Input
.env Output
How it works
Nested YAML keys are flattened with the separator. For example, database.host becomes DATABASE_HOST.
Features
- Convert flat YAML key-value pairs to .env file format
- Nested keys are flattened with configurable separator (double underscore or dot)
- Handles strings, numbers, and booleans correctly
- Filter keys by prefix to extract a subset of configuration
- Preview the resulting .env content before copying
- Copy or download the .env output
Common Use Cases
- Extract application config from YAML to .env for local development
- Convert Helm values to environment variables for container injection
- Generate .env files from configuration YAML in CI/CD pipelines
- Migrate from YAML-based config files to 12-factor app environment variables
- Create Docker run command arguments from YAML service configuration
YAML to .env Conversion
The .env file format (popularized by the dotenv library) stores configuration as KEY=VALUE pairs. It is the standard way to provide environment variables to applications following the 12-Factor App methodology.
Converting nested YAML to .env requires flattening: a nested key like database.host becomes DATABASE__HOST (using double underscore as separator, a common convention). This allows the application to reconstruct the hierarchy if needed.
Note that .env does not support arrays or complex objects β only scalar values. Array values in YAML are either joined as comma-separated strings or skipped during conversion.
Examples
database:
host: localhost
port: 5432
name: mydbDATABASE__HOST=localhost
DATABASE__PORT=5432
DATABASE__NAME=mydbFrequently Asked Questions
The most common convention is double underscore (__) because single underscore is often part of key names. Some frameworks (like ASP.NET Core, Spring Boot) use __ specifically to reconstruct hierarchy from environment variables. Use : (colon) or . (dot) only if your application framework expects it.
Most .env converters join array values as a comma-separated string (e.g., TAGS=web,api,backend). If your application expects a specific array format, you may need to post-process this manually.
Never commit .env files containing secrets. Add .env to your .gitignore. Instead, commit a .env.example file with placeholder values. Use a secrets manager (AWS Secrets Manager, Vault, etc.) for production secrets.
Yes. A common pattern: store non-secret config in YAML, convert to .env, and source it in your CI script: set -a; source .env; set +a. Secret values should come from your CI platform's secret store and be injected separately.
π‘ Tips
- Always quote values that contain spaces or special characters in .env files: <code>DB_URL="postgresql://user:pass@host/db"</code>.
- Use a prefix filter to extract only the relevant section of a large YAML file (e.g., only keys under <code>app:</code>).
- The double-underscore convention (<code>DATABASE__HOST</code>) is more portable across frameworks than using colons or dots.