Skip to content
FreeNo sign-up

.env converter

Convert a .env file to JSON, YAML, a Docker --env-file or a systemd EnvironmentFile, and back again. Each value is quoted the way the target format reads it, and values a format can't hold are listed, not silently changed.

Runs in your browser. Nothing you type is sent anywhere.

The tool is code on this page. It makes no network requests while you use it, stores nothing in cookies or local storage, and keeps working if you go offline after the page loads.

.env converter

Runs in your browser

Output: JSON

Paste a file on the left to see it converted.

Example values use Kiteline, a fictional company.

How to use it

  1. Choose the format you have and the one you need. The swap button turns the conversion around.
  2. Paste the file. The result updates as you type.
  3. Read the list under the result: it names every value that changed meaning or couldn't be written, such as a multi-line certificate going to a Docker --env-file.
  4. Copy the result. Comments and blank lines aren't carried over, only names and values.

The same without a browser

For simple files on your own machine. The Python version understands quotes; the jq versions assume plain KEY=VALUE lines.

.env to JSON with python-dotenv (pip install python-dotenv)
python3 -c "import json, dotenv; print(json.dumps(dotenv.dotenv_values('.env'), indent=2))"
JSON to .env with jq, for values without quotes or spaces
jq -r 'to_entries[] | "\(.key)=\(.value)"' env.json

How the formats differ

The same variable is written differently in each format. These are the rules the converter follows, from each format's own documentation and source.

FormatQuotesCommentsMulti-line valuesExpands $VAR
.env (dotenv)Single, double and backticks# at the start of a line, or after a spaceInside quotesDepends on the loader
Docker --env-fileNone: quotes become part of the value# at the start of a line onlyNoNo
systemd EnvironmentFileSingle (literal) and double (shell escapes)# or ; at the start of a lineInside quotesNo
JSONEvery value is a stringNoneAs \nNo
YAMLSingle and double# after a spaceAs \n in double quotesDocker Compose does, unless written $$

How Crunu handles this

Files stay in their own format

Crunu keeps env files, INI files like ~/.aws/credentials and flat YAML as they are, and shows their variables as a table. When a file has to go elsewhere, you can export an environment as one .env file, as an Ansible Vault file that opens with ansible-vault view, or as an offline copy that opens without the server. On a server, crunu pull can write an environment's variables to one file for systemd's EnvironmentFile=, with permissions 0600.

Read about export and offline copies
Example. Kiteline is a fictional company.

Questions about this tool

Found a case the tool gets wrong? Write to support@crunu.com

Why are the quotes gone in the Docker file?

docker run --env-file takes everything after = literally, quotes included: KEY="x" gives the value "x" with the quote marks. So the converter writes values without quotes, and leaves out values that span lines, which the format can't hold.

Why are numbers and true quoted in the YAML?

So they stay strings. Unquoted, YAML reads 3000 as a number and true or yes as a boolean, and a tool that reads them may write them back in another form, such as True. Environment variables are always strings.

What happens to comments?

They're dropped. The converter carries names and values only, because comments can't be represented in JSON and mean different things in the other formats.

Can it read nested JSON or YAML?

No. Environment variables are a flat list, so nested objects and lists are reported and skipped rather than flattened under invented names.

When the values need a home

Crunu is a vault for your team's environment variables and keys. Values are encrypted on your devices, so the server stores them only as ciphertext. Free during early access.