.env to JSON Converter

Convert a .env file to JSON and back with two live, editable boxes, handling quoted values, comments and the shell export keyword.

You can also drop a file onto either box.

Result: 7 lines, 132 characters

Turn a .env file into JSON, and JSON back into .env

Paste the contents of a .env file into the left box and get a clean JSON object of every key–value pair on the right. Edit either side and the other updates live, so it works both ways: you can also paste a JSON object and get a ready-to-save .env file. By default every value is kept as a string and blank lines and # comment lines are dropped — tick “Numbers, true/false and null as JSON values” or “Keep # comments (as // lines)” to change either — and each line is split on the first = so URLs and values that themselves contain an equals sign stay intact. An unquoted value ends where a space and # begin, so a trailing comment is stripped the way .env loaders strip it, while COLOR=#fff keeps its #. A leading shell export keyword is dropped, so files meant to be source-d (export DB_HOST=localhost) parse to a clean key.

Quotes and spaces handled correctly

When reading a .env file, one layer of matching surrounding quotes is stripped, so API_KEY="s3cr3t token" becomes the value s3cr3t token while the spaces inside are preserved. Going the other way, any value that contains whitespace is automatically wrapped in double quotes so the generated .env stays valid and round-trips cleanly. Copy either box with a single click. JSON layout writes the JSON Indented or on One line; a file dropped onto either box lands in that box, so a .env becomes JSON and a .json becomes .env; each box shows its line count and size under it; and “Full width, one box above the other” gives each box the whole row when a file is long.

Frequently asked questions

How are quotes and comments handled?

Lines that are blank or start with # are dropped, unless Keep # comments (as // lines) is ticked, which writes each comment as a // line above the key it stood over. For each remaining line the key and value are trimmed, one layer of matching surrounding single or double quotes is removed from the value, and in an unquoted value a space followed by # starts a comment that is left out, as .env loaders do. Values stay strings unless “Numbers, true/false and null as JSON values” is ticked, and a quoted value stays a string even then.

Can I convert JSON back into a .env file?

Yes. Edit the JSON box and the .env box updates instantly. Provide a flat object of key–value pairs; values are coerced to strings, and any value containing spaces is wrapped in double quotes so the result is a valid .env file.

Does it read Docker env files, Azure App Settings and ${VAR} references?

Yes, each as an option. Set .env format to Docker --env-file and the value is everything after the first = — quotes, # and trailing spaces included — as Docker reads it. Set JSON shape to Azure App Settings for the [{ name, value, slotSetting }] array App Service's Advanced edit uses, in both directions. And in a dotenv file, Resolve ${VAR} from keys above it expands ${VAR}, ${VAR:-default} and $VAR against keys defined earlier in the file, as dotenv-expand does. A value quoted across several lines, such as a PEM key, is read whole.

Can I get the JSON on one line, drop a file in, or see how big each side is?

Yes. JSON layout chooses Indented or One line, for the plain object and the Azure shape alike; with Keep # comments (as // lines) ticked it stays indented, since a // comment needs a line of its own. Drop a file onto either box and it lands in that box — a .env.local on the left becomes JSON, a .json on the right becomes .env — read the same way and under the same size limit as Open file, and a file that is not text is refused. Each box shows its line count and UTF-8 size beside its Copy button.

Is there a separate JSON to .env page, or a Convert or Swap button?

None is needed: this one page goes both ways, and both boxes are live. Type in the .env box and the JSON is rewritten; edit the JSON and the .env box is rewritten, so the result is already where a Swap button would put it.