.env (dotenv) Formatter & Validator
Last updated:
Paste .env content, normalize its formatting or convert it to JSON — comments and blank lines preserved. Every value stays a string, matching how environment variables actually work. All in your browser, nothing uploaded.
How it works
- Format re-serializes with normalized
KEY=valuespacing and quoting — only quoting a value when it actually needs it (empty, has leading/trailing whitespace, or contains a#that would otherwise be misread as a comment) — while keeping your comments, blank lines, and line order exactly where they were. - To JSON flattens the key/value lines into a JSON object. Unlike this site’s YAML/CSV/TOML formatters, every value stays a string — no number or boolean inference. Environment variables have no native type system;
process.env.PORTis always the string"3000", never the number, and pretending otherwise would misrepresent how these values actually behave. - Handles a leading
exportkeyword (common in .env files meant to be bash-sourced), double-quoted values with\n/\r/\"/\\escapes, single-quoted literal values, and comments — a#only starts a comment when it’s at the start of a line or preceded by whitespace, so a quoted value (or an unquoted one likeabc#defwith no space before the#) isn’t accidentally truncated.
A duplicate key doesn’t block Format or To JSON — the last definition wins, the same as real dotenv parsers do at runtime — but you’ll see a note above the output naming both lines. A duplicate key is a different kind of validator check: a key that isn’t a valid variable name (must start with a letter or underscore, then letters/digits/underscores only) IS a hard error everywhere, since that’s not valid syntax at all, not just a style risk.
Runs entirely in your browser — nothing you paste here is uploaded, logged, or stored. No autosave, by design — this is the one formatter on this site where the pasted content is almost guaranteed to contain real secrets.