Skip to content
PithLab

↑↓ to move · Enter to open · Esc to close

.env to JSON Converter (and JSON to .env)

Convert dotenv files to JSON, YAML, docker flags or Kubernetes env, and back.

Secrets stay on your device: this page converts everything in your browser and sends nothing.

Use via API

Convert a .env file to JSON, YAML, docker run -e flags or a Kubernetes env list, or a flat JSON object back to .env. Reports duplicate keys (last value wins). Send JSON, get JSON back.

POST https://pithlab.com/api/v1/tools/env-json-converter

curl https://pithlab.com/api/v1/tools/env-json-converter \
  -H "Authorization: Bearer $PITHLAB_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input":"# Database\nDATABASE_URL=postgres://localhost/app\nexport PORT=8080\nGREETING=\"Hello\\nWorld\"","to":"json"}'

Fields and responseOpenAPI documentGet an API key

About the .env to JSON Converter

Convert .env files to JSON and back, or to YAML, docker run -e flags and a Kubernetes env list. Handles quotes, comments, export and multi-line values in your browser.

How to use the .env to JSON Converter

  1. Choose whether your input is a .env file or a JSON object.
  2. Paste it in, or press Example to see comments, quotes and a multi-line value.
  3. Pick the output: JSON, .env, YAML, docker run -e flags or a Kubernetes env list.
  4. Check the warnings for repeated keys or values that changed, then copy or download the result.

Examples

.env with comments, quotes and a repeated key to JSON

Input

# Database
export DB_HOST=localhost
DB_PORT=5432 # default port
DB_PASS='p@ss#word'
GREETING="Hello\nWorld"
URL=https://example.com/#top
DB_PORT=6543

Output

{
  "DB_HOST": "localhost",
  "DB_PORT": "6543",
  "DB_PASS": "p@ss#word",
  "GREETING": "Hello\nWorld",
  "URL": "https://example.com/#top"
}
JSON to .env, quoting only where needed

Input

{"PORT": 8080, "DEBUG": false, "TITLE": "My App", "MOTD": "Line 1\nIt's line 2", "EMPTY": null}

Output

PORT=8080
DEBUG=false
TITLE='My App'
MOTD="Line 1\nIt's line 2"
EMPTY=
JSON to docker run flags

Input

{"NODE_ENV": "production", "GREETING": "it's live"}

Output

-e NODE_ENV=production \
-e 'GREETING=it'\''s live'

Frequently asked questions

When does # start a comment?

A line starting with # is a comment. In an unquoted value, # only starts a comment when there is a space before it, so URL=https://example.com/#top keeps the #. Inside quotes, # is always part of the value.

How do quotes and escapes work?

Single quotes and backticks keep the value exactly as written. Double quotes understand \n, \r, \t, \" and \\. Any quoted value may span several lines, which is handy for private keys. Variables like ${HOME} are kept as text, not expanded.

What happens when a key appears twice?

The last value wins, as with most dotenv loaders, and a warning lists the line numbers so you can tidy the file.

How are JSON numbers, booleans and objects handled?

Environment variables are always text, so 8080 becomes "8080" and false becomes "false". null becomes an empty value, and nested objects or arrays are written as JSON strings with a warning.

Is it safe to paste real secrets?

Everything runs in your browser and nothing is sent or stored, so secrets stay on your device. Even so, rotate any secret you have pasted somewhere you do not fully control.