deftools.io Developer Tools

🔧 .env Converter

Convert .env files to JSON, YAML, Docker Compose, shell export, or systemd — and convert JSON back to .env.

About this tool

Convert a .env file into JSON, YAML, a Docker Compose environment: block, shell export statements, or a systemd Environment= line — and back into a clean, normalized .env. It also works in reverse: paste a JSON object and it converts to any of the output formats including .env. It correctly parses quoting (single and double), inline # comments, the export prefix, escape sequences like \n, and multiline values.

Example input (.env):

export PORT=3000
API_KEY="sk-1234 # not a comment"
DEBUG=false

Produces (JSON output):

{
  "PORT": "3000",
  "API_KEY": "sk-1234 # not a comment",
  "DEBUG": "false"
}

You can also paste a JSON object as input — handy when copying environment variables from a dashboard (Vercel, AWS, etc.) into a local .env file:

{"PORT": 3000, "DEBUG": true, "API_KEY": "sk-1234"}

Produces (.env output):

PORT=3000
DEBUG=true
API_KEY="sk-1234"

Toggle Sort keys to alphabetize variables, Strip export to drop the export keyword on output, or Drop comments to omit # lines entirely. The .env (normalized) format re-quotes values that contain spaces or special characters so the file round-trips safely.

FAQ

Can I convert JSON back to .env?

Yes. Paste a JSON object (e.g. {"PORT":3000,"DEBUG":true}) into the input — the tool auto-detects it and converts to any output format including .env. Numbers and booleans are stringified to match .env semantics; nested objects become JSON strings.

How are quoted values handled?

Single-quoted values ('foo') are treated literally — no escape expansion and # is kept as a character. Double-quoted values ("foo") expand backslash escapes like \n, \t, \" and treat # as a literal character rather than a comment. Unquoted values end at the first whitespace-then-# sequence, which becomes an inline comment.

What does .env (normalized) do?

It re-emits a clean .env file from the parsed variables. Values containing spaces, quotes, #, $ or backslashes are wrapped in double quotes; multiline values escape newlines as \n. This is useful for cleaning up hand-edited .env files that mix export prefixes, inconsistent quoting, and stale comments.

Are values typed (numbers, booleans)?

No. All .env values are strings, so JSON output preserves them as strings ("PORT": "3000") rather than coercing to numbers. YAML output quotes values that would otherwise be interpreted as booleans or numbers (e.g. "false", "3600") to prevent silent type coercion when the YAML is loaded.

How does systemd format work?

systemd service files use a single Environment= directive with space-separated KEY=value pairs. Values containing spaces or special characters are wrapped in double quotes with backslash escaping. Multiline values are not supported by systemd and should be avoided.

More developer tools

Copied!