.env syntax rules
# Comments start with #
PORT=3000 # inline comment after a space
export NODE_ENV=production # "export" prefix is allowed
EMPTY= # empty string
# Double quotes: escapes (\n, \t, \") are decoded, # is literal
GREETING="Hello\nWorld"
URL="https://example.com/#anchor"
# Single quotes: everything literal, no escapes
PATTERN='^\d+$'
# Multi-line values (e.g. keys) need quotes
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIIEv...
-----END PRIVATE KEY-----"
Output formats
- JSON: for config loaders, AWS Secrets Manager, Vercel and Netlify APIs, or tests.
- YAML: for Helm values, Ansible vars or Docker Compose
environment:blocks. - docker -e: ready-to-paste flags, quoted for the shell.
-
Kubernetes env: a
name/valuelist for a container spec. For real secrets, prefer a Secret withenvFrom:
# Create a Kubernetes Secret straight from a .env file
kubectl create secret generic app-env --from-env-file=.env
Best practices for .env files
- Add
.envto.gitignore, and commit a.env.examplewith placeholder values instead. - Use UPPER_SNAKE_CASE names with only letters, digits and underscores, so every shell and tool accepts them.
- Define each key once. With duplicates, the last one wins, and the tool warns you about them.
- Quote any value containing spaces,
#, quotes or line breaks.
Moving a container setup to Compose? Try docker run to Compose.
Frequently asked questions
How do I convert a .env file to JSON?
Paste the contents of your .env file into the tool above, or drop the file onto it, and choose JSON. Each KEY=value line becomes a JSON property. Comments and blank lines are ignored, and quoted and multi-line values are decoded the same way the dotenv library does.
Is it safe to paste my .env file here?
The conversion runs entirely in your browser: nothing is uploaded, logged or stored, and this tool has no share-link feature, so secrets are never put in a URL. Still, treat .env files like passwords. Rotate any secret that has been exposed somewhere it shouldn’t be.
How are quotes and # comments handled?
In unquoted values, # starts a comment even without a space, so PORT=3000#web becomes 3000. Quote values containing a literal #. Inside double quotes, # is kept and escapes like \n are decoded. Single-quoted values are taken literally. Double- and single-quoted values may span multiple lines, which is useful for private keys.
Does it expand variables like ${HOME}?
No. Like dotenv itself, values are kept as written. Expansion is done by dotenv-expand, Docker Compose or your shell, and each handles it slightly differently.
How do I turn JSON config into a .env file?
Switch to "JSON → .env". Nested objects are flattened with underscores and keys are converted to UPPER_SNAKE_CASE, so {"database": {"host": "db"}} becomes DATABASE_HOST=db. Values with spaces or special characters are quoted and escaped.