Ennadia
Text & Data

ENV to JSON

Reshape environment variables without leaving the tab.

  • Local by default
  • No signup
  • AI is opt-in

Output

 

Parsing follows common dotenv rules: export prefixes, # comments, single-quoted literals and double-quoted escapes. .env is not a formal standard, so other loaders may differ.

Convert a .env file into a JSON object you can inspect or import, and turn a flat JSON object back into dotenv syntax. Quoting, escapes, comments and export prefixes are handled locally — the file never leaves your browser.

.env is a convention, not a specification

There is no RFC for .env files. The format grew out of libraries such as dotenv, and every loader — the Node dotenv package, Docker --env-file, Python dotenv, Rails, deployment platforms — implements a slightly different dialect. The common core is simple: one KEY=VALUE pair per line, blank lines and # comments ignored.

This page follows the most common dotenv behaviour, which is also the most forgiving: optional export prefix, single quotes for literal values, double quotes for escapes, and unquoted values trimmed at the ends. If your loader disagrees about a corner case, trust the loader and use the converter as a starting point rather than an authority.

How a line is read

  1. Blank lines and lines whose first non-space character is # are skipped.
  2. export KEY=VALUE is accepted; the prefix is not part of the key.
  3. The key must match [A-Za-z_][A-Za-z0-9_]*. Anything else is reported with its line number.
  4. A double-quoted value is unescaped: \n, \r, \t, \" and \\ become their characters.
  5. A single-quoted value is literal. No escape processing happens inside it.
  6. An unquoted value has surrounding whitespace removed, and a # preceded by whitespace starts a comment.
NODE_ENV=production
GREETING="hello\nworld"
LITERAL='hello\nworld'
URL=https://example.com/#anchor   # comment

In the example above, GREETING contains a real newline, LITERAL contains the two characters backslash and n, and the #anchor inside the URL survives because it is not preceded by whitespace.

Writing JSON back to .env

Going the other way is about knowing when a value needs quotes. A value may be written bare only if it has no whitespace and no character that a loader or shell would interpret: #, $, quotes, backslashes and newlines all require quoting. Empty values are written as "" for clarity.

Inside double quotes, backslashes, double quotes, newlines, carriage returns and tabs are escaped. That produces output that most dotenv parsers read back to the same value. It does not guarantee identical behaviour in a shell: source .env performs its own expansion and treats $ differently, so a value containing a dollar sign may still be expanded when sourced.

Nested JSON values have no dotenv equivalent. Arrays and objects are rejected with an error rather than flattened silently; flatten them into separate keys such as DATABASE_HOST and DATABASE_PORT first.

Loaders differ in ways that matter

  1. dotenv (Node/Python): supports quoted values, comments and multi-line values in some versions; duplicate keys usually keep the last value.
  2. Docker --env-file: does not support export, and quoting rules are stricter; a stray quote becomes part of the value.
  3. Shell source: runs the file as shell code, so $VAR expands and command substitution can execute. Never source an untrusted file.
  4. Platform dashboards: store key/value pairs in a UI, not as a file. Pasting dotenv text into one often keeps quotes literally.

Because of these differences, the safest pipeline is to keep one canonical source (usually the platform secrets store), export it as key/value pairs, and generate any .env file for local development from that source. Converting by hand invites drift.

Values that still break

  1. Multi-line values written across several physical lines are not supported here; use \n inside double quotes instead.
  2. Values containing $ may be expanded when the file is sourced by a shell, even though dotenv would keep them literal.
  3. Duplicate keys are resolved last-wins, matching common loaders, but the page reports them so you can remove the ambiguity.
  4. A # with no preceding whitespace stays in the value; a loader that strips every # will disagree.
  5. Very long values are fine for the parser but may hit platform limits when pasted into a dashboard.

Secrets and this page

A .env file is usually where production credentials live. This page is designed for the opposite situation: you already have the file on your machine and need to inspect or reshape it. Parsing and serialising happen in the tab, with no upload request and no logging. There is no analytics event that includes the content.

That does not make it safe to paste secrets into any web page. A browser extension, a compromised dependency or a shared screen can still expose the text. If a value is highly sensitive, rotate it after use and keep it out of screenshots and chat logs.

Frequently asked questions

Does the converter support the export prefix?

Yes. export KEY=VALUE is parsed the same as KEY=VALUE when converting to JSON, and the JSON to ENV direction can add the prefix to every line with a checkbox.

How are comments handled?

Full-line comments starting with # are ignored. In unquoted values, a # preceded by whitespace starts a comment. Comments are not preserved in the JSON output because JSON has no comment syntax; they are lost when converting back.

Why did my quoted value lose its quotes?

Quotes are syntax, not data. A double-quoted value is unescaped and a single-quoted value is kept literal, but the quote characters themselves are removed. When converting back, the serializer adds quotes only where a loader needs them.

Which value wins when a key appears twice?

The last occurrence wins, which matches common dotenv implementations. The status line lists the duplicated keys so you can remove the ambiguous entry.

Can a value span multiple lines?

Not in this tool. A physical newline ends the pair. Write the newline as \n inside a double-quoted value and it will be unescaped into a real newline in JSON. Some dotenv implementations support multi-line quoted values, but support is inconsistent.

Is my .env file uploaded anywhere?

No. Parsing and serialisation use plain JavaScript in the browser. There is no network request while converting, so the content stays on your device.