Convert .env to JSON — and back — without breaking quotes
Environment files look simple until a value contains a space, a #, a dollar sign, a quote or a multi-line private key. This .env to JSON converter parses dotenv files the way the popular dotenv libraries do — export prefixes, comments, single, double and backtick quotes, escaped \n, values that span several lines, and optional ${VAR} / ${VAR:-default} expansion — and turns them into JSON, YAML, shell export lines or docker run -e flags.
It works in the other direction too: paste a JSON or YAML object (nested keys are flattened with __, _ or .) or a docker command and get a clean .env file with every value quoted only when it has to be. A table lists every variable with notes such as “multiline”, “expanded” or “empty”, and warnings point out duplicate keys, undefined references and lines that are not KEY=value.
Secrets stay on your machine: conversion runs in your browser and, by default, values whose names look like passwords, tokens or keys are masked in the on-screen preview.
How to use the .env to JSON Converter
- Paste your
.env, JSON, YAML, export lines or docker command into Input, or press Load .env file. The format is detected automatically; override it with Input format. - Pick the output with the JSON, .env, YAML, export or docker -e switch.
- Choose options: expand
${VAR}references, mask secrets in the preview, sort keys, keep comments, or emit numbers and booleans as typed JSON/YAML values. - Check the variables table and any yellow warnings.
- Press Copy output or Download — both always contain the real, unmasked values. Use output as input lets you chain another conversion.
.env to JSON Converter features
dotenv-compatible parsing
Comments, blank lines, export KEY=, inline # comments after unquoted values, double quotes with \n \t \" \\ \$ escapes, literal single and backtick quotes, and quoted values spanning multiple lines.
Variable expansion
$VAR, ${VAR}, ${VAR:-default} and ${VAR-default} are resolved against variables defined earlier in the file, as dotenv-expand and Docker Compose do. Single-quoted values are never expanded.
Five output formats
Pretty JSON, a re-quoted .env, YAML with safe quoting (so no stays a string), POSIX shell export lines, and a docker run command with one -e flag per variable.
Round-trip safe
Values are quoted only when needed and escaped so that converting .env → JSON → .env gives the same values back, including quotes, dollar signs and newlines.
Secret masking
Keys containing PASSWORD, SECRET, TOKEN, KEY, AUTH, DSN and similar are masked in the preview and table, so you can share your screen; Copy and Download keep the real values.
How values are quoted in the generated .env
| Value | Written as | Why |
|---|---|---|
production | APP_ENV=production | Safe characters only — no quotes needed |
My App | APP_NAME='My App' | Contains a space; single quotes keep it literal |
p@ss#word$1 | DB_PASSWORD='p@ss#word$1' | # would start a comment and $ would expand |
it's | QUOTE="it's" | Contains a single quote, so double quotes are used |
| two lines | KEY="line1\nline2" | Newlines are escaped so the file stays one line per variable |
| (empty) | EMPTY= | An empty value is defined but blank |
Where each output format is useful
- JSON — AWS Secrets Manager and Parameter Store imports, Vercel and Netlify APIs, Node
configfiles, or anything you load withJSON.parse. Tidy it further with the JSON Formatter. - YAML — Kubernetes ConfigMaps and the
environment:block of a compose file; see the Docker Compose generator. - export — paste into a terminal or
sourcea script to set variables for the current shell session. - docker -e — a quick
docker runfor testing; for real deployments prefer--env-file .envso secrets do not end up in your shell history. - .env — normalise a messy file, convert JSON settings for a framework such as Laravel, Next.js, Vite or Django-environ, or produce a template for teammates.
Differences between dotenv implementations
Not every loader reads .env files identically. Node’s dotenv (v15+) supports multi-line quoted values and backticks; Python-dotenv and Docker Compose support ${VAR} expansion natively, while Node needs dotenv-expand. Docker’s own --env-file is the strictest: it does not strip quotes or support multi-line values at all. If a file must work everywhere, keep values on one line, avoid quotes where possible and prefer plain KEY=value, which is what this converter writes whenever it can.
.env to JSON Converter FAQ
How do I convert a .env file to JSON?
Paste the file into the input (or load it), keep the output on JSON, and copy or download the result. Comments are dropped because JSON has none, quoted values are unquoted, and ${VAR} references are expanded if that option is on.
Can I convert JSON to .env with this .env to JSON converter?
Yes. Paste a JSON object and choose the .env output. Nested objects become keys joined with __ (for example db.host → db__host), which frameworks such as ASP.NET Core and many config libraries map back to nested settings.
Are my secrets uploaded?
No. Parsing and conversion run entirely in your browser; nothing is sent to a server. The masking option only changes what is displayed, not what you copy.
Why is my variable empty after conversion?
Most often it references another variable that is defined later in the file, or not at all — expansion only sees variables above the current line. The warnings list names the missing variable. Turn off expansion to keep ${VAR} as literal text.
How are multi-line values such as private keys handled?
Double- or single-quoted values may span several lines and are read as one value. In the .env output they are written on one line with \n escapes, which dotenv libraries turn back into real newlines.
Does the order of variables matter?
Only for expansion: a variable can reference those defined before it. Sorting keys A–Z disables comment preservation, since comments would no longer sit next to the right variables.