Loading YAML to Environment Variables Converter...
Please wait a moment

How to Convert YAML to Environment Variables - Step by Step Guide

Step 1

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"
Step 2

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'
Step 3

Customize Naming Options

Three options shape the names: the separator between key levels, an optional prefix, and whether names are uppercased.

•
Uppercase keys: on by default (DATABASE_HOST); turn it off to keep the YAML spelling (database_host)
•
Separator: Underscore (_), dash (-), or dot (.)
•
Prefix: Add custom prefix (e.g., MYAPP_, PROD_)
•
Nested Keys: Flatten with separators (database_host vs DATABASE_HOST)
•
Lists: each item is named by its position (TAGS_0, TAGS_1)
Step 4

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=3000

Kubernetes 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.