.env Converter
runs in your browserConvert a .env file to JSON or YAML and back, keeping the quoting rules that decide whether \n is a newline or two characters.
Inside double quotes \n is a newline; inside single quotes it is two characters. That difference is kept, which matters when the value is a key.
.env
JSON
about this tool
.env, JSON and YAML, in any direction
Paste one, pick the other. The format you pasted is worked out from the text rather than from what you told it, so the usual case is paste and read.
The quoting rule this tool exists for
Inside double quotes, \n is a newline. Inside single quotes, it stays
as the two characters you typed.
That difference is the whole reason converting a .env by hand goes wrong. The
most common multi-line value in a real file is a private key, and a converter
that treats the two quote styles alike will silently rewrite it — producing a
file that looks fine and does not work. Both rules are kept here, in both
directions.
Writing back out, a value is only quoted when it needs to be, and a newline inside it is escaped rather than breaking the file across two lines.
Everything is a string
Environment variables have no types. PORT=3000 is four characters, not a
number, so the JSON output says "3000".
This looks like a bug and is the opposite. Turning it into a JSON number would invent information the file never carried, and converting back would then have to guess whether to quote it.
What cannot be carried
A .env is flat. Converting JSON that has nested objects or lists in it leaves
those out and tells you which — flattening them into DOTTED_NAMES would create
keys that were never in your config, and the version that came back would not
match the one you started with.
Keys that a shell would refuse — starting with a digit, containing a hyphen — are skipped for the same reason, with the line number.
Nothing leaves your browser
Worth stating plainly here more than on most pages: a .env is usually the most
sensitive file in a project. It is parsed and converted in this page, nothing is
uploaded, and nothing is stored.
For converting between JSON and YAML on their own, use JSON to YAML.
questions
- Why do single and double quotes behave differently?
- Because they do in dotenv, and in the shell it copies. Inside double quotes \n is a newline; inside single quotes it stays as the two characters you typed. A converter that treated them alike would quietly rewrite any value holding a private key, which is the most common multi-line value in a real .env.
- Is my .env uploaded anywhere?
- No. It is parsed and converted in this page and nothing is sent or stored. Worth saying on this tool in particular, since a .env is usually the single most sensitive file in a project.
- What happens to nested objects when I convert JSON to .env?
- They are left out and listed, because a .env is flat and cannot hold them. Flattening them into DOTTED_NAMES would invent a key that was never in your config, which is worse than telling you plainly what could not be carried.
- Why is every value a string in the JSON output?
- Because every value in a .env is a string. Environment variables have no types — PORT=3000 is the four characters 3, 0, 0, 0, not the number — so turning it into a JSON number would be inventing information the file never held.
- Does it handle export, comments and multi-line values?
- Yes. A leading export is accepted because that is how people paste from a shell, a # starts a comment outside quotes, and a quoted value may run over several lines so a PEM key survives intact. Anything it cannot read is skipped with the line number rather than dropped in silence.