Output appears here.
The .env Formatter normalizes dotenv files: it trims spacing around =, quotes values only where needed, collapses stray blank lines and flags duplicate or invalid keys. It can also produce a .env.example with every secret removed, or convert the file to JSON. Everything runs in your browser — nothing is uploaded.
How to format and validate a .env file
- Paste the contents of
.env,.env.localor.env.example, or drop the file itself. - Choose a mode — Format, Make .env.example or To JSON — and set Quote values. Invalid lines stop the output and are listed with line numbers; duplicate keys are reported as notices.
- Copy or download the result. After formatting, the Next actions Make .env.example and Convert to JSON switch mode without re-pasting.
Examples
A messy .env
Spaces around = and before a key are removed, two blank lines become one, the value with a space stays quoted, export is kept, and the empty value stays empty:
# Database
DB_HOST = localhost
DB_PORT=5432
DB_PASSWORD="s3cr3t value"
API_URL=https://api.example.com
export NODE_ENV=production
DEBUG=Result:
# Database
DB_HOST=localhost
DB_PORT=5432
DB_PASSWORD="s3cr3t value"
API_URL=https://api.example.com
export NODE_ENV=production
DEBUG=A .env.example without secrets
The same file in Make .env.example mode. Keys, comments and grouping stay; every value is removed, so the file is safe to commit:
# Database
DB_HOST=
DB_PORT=
DB_PASSWORD=
API_URL=
export NODE_ENV=
DEBUG=Duplicate keys
A repeated key is valid syntax, but only one value is used. The file is formatted and a notice names both lines:
PORT=3000
HOST=0.0.0.0
PORT=8080Notice: "Duplicate key PORT on lines 1 and 3 — the last value wins in most loaders."
An invalid key
Keys cannot contain spaces. Adding BAD KEY=value to the file above stops formatting with:
Invalid key `BAD KEY` on line 4.
Hint: Keys may contain letters, digits and underscores, and cannot start with a digit or contain spaces.Options explained
- Sort keys — orders variables alphabetically. The output then contains only the
KEY=valuelines; comments and blank-line grouping are dropped, and when the file had comments a notice says "Sorting keys removes comments and blank lines." Use it for generated files rather than hand-maintained ones. - Quote values — When needed adds double quotes only to values with spaces,
#, quotes,$, backticks, backslashes or=; Always quotes every value; Never writes simple values bare but still quotes any value that needs it, and a notice says so. Single-quoted values keep their single quotes, so variables inside them are never expanded; empty values stay empty unless you choose Always. - Remove export prefix — drops
exportfrom lines such asexport NODE_ENV=production, for loaders that do not accept it.
Common .env errors
"Line N is not KEY=value"
The line is neither a pair, a comment nor blank — often a pasted shell command, a YAML-style KEY: value, or a value that continues onto the next line without quotes. Use =, and wrap multi-line values in double quotes.
"Invalid key"
Keys must start with a letter or underscore and contain only letters, digits and underscores (dots and hyphens are tolerated). 1BAD and BAD KEY are rejected. Most shells cannot export such names either.
Part of a value was treated as a comment
In an unquoted value, a # preceded by a space starts a comment: GREETING=hello world # note keeps the comment separately. PATH_X=a#b has no space before #, so it stays part of the value and is quoted in the output to make that explicit.
Values are still quoted with "Never"
Quote values set to Never removes quotes only where they are optional. A value such as hello world or a#b would change meaning without them, so it stays quoted and the notice "Some values contain spaces or special characters, so they were quoted anyway." appears. Remove the spaces or special characters if a tool rejects quotes.
A value with $ was expanded by the loader
Loaders that expand variables do so inside double quotes but not inside single quotes. The formatter keeps single quotes as they are, so SINGLE='$HOME/x' stays literal. If you wrote the value in double quotes or bare, switch it to single quotes in the source.
FAQ
What is a .env file?
A .env file holds environment variables for local development as KEY=value lines, with # comments. Libraries in Node.js, Python, Ruby, PHP and Go load it at startup, and tools such as Docker Compose read it directly. It usually contains secrets, so it is kept out of version control while a .env.example documents the expected keys.
How do I create a .env.example file?
Paste your .env and choose Make .env.example. Every value is removed while keys, comments, export prefixes and blank-line groups remain, and the notice confirms "Values removed — safe to commit as .env.example." Review the comments too, since a comment could itself contain a secret.
Should values in a .env file be quoted?
Quote values that contain spaces, #, quotes, $ or line breaks; others can stay bare. Double quotes allow escapes such as \n, and many loaders expand ${VAR} inside them. Single quotes are taken literally by most loaders. When needed, the default, follows these rules.
Which value wins when a key is duplicated?
It depends on the loader. Most dotenv libraries and Docker Compose use the last occurrence, some use the first, and a shell source also takes the last. Because the behaviour varies, the formatter reports every duplicate so you can remove the ambiguity rather than rely on it.
How do I convert a .env file to JSON?
Choose To JSON. Each variable becomes a string property, in file order, with quotes removed and escapes such as \n expanded; comments are dropped. Empty values become "". All values are strings, because environment variables are always text.
Is it safe to paste real secrets here?
The file never leaves your browser: the formatter runs in an isolated frame that blocks network requests, and nothing is sent or logged. Content is not stored unless you turn on "Remember my last input", so leave that off when pasting secrets on a shared computer.
Related tools
Other config formats have their own formatters: the YAML Formatter, the TOML Formatter and the JSON Formatter. If a file has Windows line endings, fix them with the Line Ending Converter.