.env to JSON Converter
Convert .env files to JSON and JSON back to .env, with a linter that flags duplicate keys, invalid names, unquoted spaces, and other dotenv pitfalls. Values can be masked on screen.
Processed locally in your browser — nothing is uploaded.
.env to JSON Converter
0 characters
JSON
Output appears here…About the .env to JSON Converter
Paste a .env file and get its variables as a JSON object — ready for a secrets manager import, a vercel.json or app.json, a test fixture, or a quick look at what your app will actually see. Switch to JSON → .env to go the other way: nested objects are flattened into names like DATABASE_HOST, camelCase keys become UPPER_SNAKE_CASE, and any value with spaces, quotes, $, #, or line breaks is quoted so it reads back the same in every loader.
Underneath is a dotenv parser with a linter attached. .env has no formal specification, and Node's dotenv, python-dotenv, Docker Compose, and source .env in a shell each read the same file a little differently. The parser follows the rules they share; the Lint panel points at every line where they'd disagree, or where the file probably doesn't mean what it says.
What the parser understands
KEY=valuelines, blank lines,# comments, and an optionalexportprefix- Unquoted values are trimmed, and a
#after whitespace starts an inline comment —URL=https://x.dev/#/routekeeps its# 'single'and`backtick`quotes are literal: no escapes, no variable expansion"double"quotes process\n,\r,\t,\",\\, and\$- Any quoted value can span several lines, which is how private keys and certificates are usually stored
- If a key appears twice, the last value wins — the duplicate is flagged either way
- With Expand ${VAR} references on (in Options),
${VAR},$VAR,${VAR:-default}and${VAR-default}are replaced in unquoted and double-quoted values, using keys defined above the reference — the way Docker Compose anddotenv-expanddo it
What the linter checks
- Duplicate keys, with the line the key was first set on
- Invalid names:
MY KEYis an error and the line is skipped; names with dots or dashes, or that start with a digit, work in Node'sdotenvbut not in a shell ordocker --env-file, so they're a warning - Unquoted values with spaces or
#, which different loaders cut in different places - Trailing whitespace, which loaders silently strip from unquoted values
- Empty values, spaces around
=, unclosed quotes, text after a closing quote,KEY: valuelines, and references to variables that aren't defined yet
Masking values
Turn on Mask values before sharing your screen or taking a screenshot: every value in the output is replaced with a fixed-width row of dots, so not even its length shows. Copy and Download still give you the real values, and the lint messages never quote a value in the first place.
Example
Input
# Database DB_HOST=localhost DB_PORT=5432 export API_KEY="sk_test_123" # test key APP_NAME=My App
Output
{
"DB_HOST": "localhost",
"DB_PORT": "5432",
"API_KEY": "sk_test_123",
"APP_NAME": "My App"
}Every value is a string, because environment variables are strings. The linter adds a warning for line 5: My App contains a space but isn't quoted.
Limitations
- Values always become JSON strings —
5432andtruestay"5432"and"true", exactly as a program reads them from the environment. - Expansion only sees variables defined earlier in the same file, not your shell's environment, and command substitution like
$(whoami)is never run. - Going from JSON to
.env, names that aren't valid variable names are rewritten (api-keybecomesAPI_KEY), and the tool lists every rename. Two keys that would end up with the same name are refused rather than silently merged.
Frequently asked questions
How do I convert a .env file to JSON?
Paste the file into the .env box and the JSON object appears as you type, with every variable as a string. Copy it or download it as env.json. Comments, blank lines, and export prefixes are handled, and multi-line quoted values come out as strings with \n line breaks.
How do I convert JSON to a .env file?
Switch to the JSON → .env tab and paste a JSON object. Nested objects and arrays are flattened into names like DATABASE_HOST and FEATURES_0, or kept as JSON strings if you choose that in Options. Values with spaces, quotes, $ or line breaks are quoted so they read back unchanged.
Should values in a .env file be quoted?
Quote any value that contains spaces, #, quotes, $ or line breaks. Unquoted, loaders disagree: Node's dotenv cuts a value at #, a shell splits it at spaces, and Docker Compose expands $. Use single quotes for a literal value and double quotes when you need escapes like \n. The linter flags unquoted values that need quotes.
Can a .env value span multiple lines?
Yes, inside quotes. A double- or single-quoted value can continue over several lines until its closing quote, which is the usual way to store a PEM private key. Alternatively, write it on one line in double quotes with \n escapes. An unclosed quote is reported as an error.
What happens with duplicate keys in a .env file?
Node's dotenv, python-dotenv, and Docker Compose all use the last value, so that's what the JSON shows. The linter flags every repeat with the line where the key was first set, since a duplicate is almost always a leftover from copying one config into another.
Does it expand ${VAR} references?
Only if you turn on "Expand ${VAR} references" in Options, since Node's dotenv doesn't do it by default. When on, ${VAR}, $VAR, ${VAR:-default} and ${VAR-default} are replaced in unquoted and double-quoted values using variables defined above them. Single-quoted values and \$ stay literal.
What makes a valid environment variable name?
Letters, digits, and underscores, not starting with a digit — like DATABASE_URL. Node's dotenv also accepts dots and dashes, but a shell, docker --env-file, and most process managers don't, so the linter warns about them. A name with a space or other symbol is an error.
Is my .env file sent anywhere?
No. Parsing, linting, and conversion run entirely in your browser, which is the only sensible way to handle a file full of API keys and database passwords. Turn on Mask values to hide them on screen as well.