YAML to Environment Variables Converter - Generate .env Files Online
Convert YAML configuration files to environment variables in multiple formats (.env, shell export, Docker ENV, JSON). Pick the separator, add a prefix and choose whether names are uppercased.
YAML to environment variables, YAML to env vars, YAML to .env file, YAML to shell export, YAML to docker env, YAML config converter, environment variables generator, YAML to env converter
How to Convert YAML to Environment Variables - Step by Step Guide
Input Your YAML Configuration
Ready to convert your YAML configuration files for Docker Compose, Kubernetes containers, or .env files to environment variables? Just paste your YAML content. The converter flattens nested structures and writes one variable per value, named after its path in the YAML. After conversion, use YAML validator to check your source or convert to JSON for API usage.
Example: Application Configuration
Here's a typical YAML config file:
# Application Configuration app: name: "MyApp" version: "2.1.0" debug: true server: host: "0.0.0.0" port: 3000 ssl: enabled: true cert_path: "/etc/ssl/certs/app.crt" database: host: "postgres.example.com" port: 5432 credentials: username: "db_admin"
Choose Output Format
Pick the format that matches where the variables are going: .env lines, shell exports, Docker ENV commands, or JSON format for different deployment scenarios.
Available Output Formats
Choose the format that works best for your deployment:
.env File Format:
APP_NAME=MyApp APP_VERSION=2.1.0 APP_DEBUG=true SERVER_HOST=0.0.0.0 SERVER_PORT=3000
Shell Export Format:
export APP_NAME='MyApp' export APP_VERSION='2.1.0' export APP_DEBUG='true' export SERVER_HOST='0.0.0.0' export SERVER_PORT='3000'
Customize Naming Options
Three options shape the names: the separator between key levels, an optional prefix, and whether names are uppercased.
Export & Deploy
Copy the variables or download them as a file for Docker, Kubernetes, a CI/CD pipeline or local development.
Deployment Examples
Here's how to use your environment variables:
Docker Compose:
services:
app:
env_file: .env
# or inline:
environment:
- APP_NAME=MyApp
- SERVER_PORT=3000Kubernetes ConfigMap:
kubectl create configmap app-config \ --from-env-file=.env
Frequently Asked Questions
How are nested keys and lists turned into variable names?
Each level of the YAML path is joined with the separator you pick, so database.credentials.username becomes DATABASE_CREDENTIALS_USERNAME. List items take their position as part of the name: tags: [api, web] gives TAGS_0=api and TAGS_1=web.
Which output formats can I pick, and how are values quoted?
You get .env lines, shell export lines you can source in bash, Dockerfile ENV lines, or a flat JSON object. The export lines use single quotes, so a $, a backtick or a $(...) in a value is never expanded or run by the shell. Dockerfile ENV lines escape ", \ and $, and a line break, which an ENV line can't hold, is written as \n with a note.
Will values like 00501 or 14.50 change?
No. Every value is written as it appears in the YAML. 00501 keeps its leading zeros, 14.50 keeps its trailing zero, 1e3 stays 1e3, a 19-digit ID such as 8901240544102066246 keeps every digit, and dates like 2024-01-15 stay as written. A null becomes an empty value.
What happens to keys that aren't valid variable names?
Accented letters lose the accent, characters such as spaces or dashes become an underscore, and a name that starts with a digit gets an underscore in front. If two YAML keys end up with the same variable name, the second one gets _2 on the end instead of overwriting the first. A note above the output lists every rename.
Can I add a prefix to every variable?
Yes, type it in the Prefix box. With MYAPP as the prefix, database.host becomes MYAPP_DATABASE_HOST. If you type MYAPP_ with the separator already on the end, it isn't doubled.
Does the output work with Docker Compose and Kubernetes?
The .env output can be loaded with env_file in Docker Compose. kubectl create configmap --from-env-file takes every line literally, quotes included, so it suits values that didn't need quoting. One thing to know about python-dotenv: it expands ${NAME} inside values even when they are quoted, so load the file with interpolate=False if your values contain a literal ${. The conversion runs in your browser and your YAML isn't uploaded.