How to use the .env to JSON converter
- Paste a
.envfile into the left pane. The JSON appears as you type. - Values: Keep as strings (the default) or Numbers & booleans to type unquoted numbers and
true/false. - Nesting (under More options): Flat keys, or Split on __ to turn
DB__HOSTinto{"DB": {"HOST": …}}, the convention used by .NET configuration and many Node.js config libraries. - Copy or Download the result as
env.json.
Example
# .env for local development
PORT=3000
DATABASE_URL="postgres://app:change-me@localhost:5432/app"
REDIS_URL=redis://localhost:6379 # cache
export API_BASE_URL=https://api.example.com/v2
GREETING="Hello\nWorld"
EMPTY=
becomes
{
"PORT": "3000",
"DATABASE_URL": "postgres://app:change-me@localhost:5432/app",
"REDIS_URL": "redis://localhost:6379",
"API_BASE_URL": "https://api.example.com/v2",
"GREETING": "Hello\nWorld",
"EMPTY": ""
}
Syntax it understands
KEY=value, with an optionalexportprefix as used in shell scripts, andKEY: valueas an alternative separator.- Comments: lines starting with
#, and inline comments after whitespace in unquoted values. - Double quotes understand the escapes
\n,\r,\t,\",\\and\$. - Single quotes and backticks keep the text exactly as written.
- Multi-line values inside quotes, such as a PEM private key spread over several lines.
- Empty values (
EMPTY=) become empty strings.
Lines that are not KEY=value, invalid variable names (they must start with a letter or _) and unclosed quotes are errors that point to the exact line.
When to use it
- Checking what a program will see, including where inline comments end and how quotes are read.
- Moving config into JSON-based systems such as cloud secret managers, Kubernetes ConfigMaps or app settings files.
- Comparing environments. Convert two
.envfiles and compare them in JSON Diff.
Common pitfalls
Different tools read .env files slightly differently, which is a frequent source of “works on my machine” bugs. The npm dotenv package, Docker Compose, Python’s python-dotenv and shell source disagree on inline comments, on whether single quotes allow escapes and on variable expansion. This tool follows the most widely shared rules and tells you when a value refers to another variable, so you can check how your runtime will treat it. When a value contains a space, a # or a quote, quote it in the file to make every reader agree.
Need the reverse? Click Reverse above the output or open JSON to .env. To produce YAML or TOML from a .env file instead, use the Data Format Converter, and to tidy the result use the JSON Formatter.
Frequently asked questions
Is it safe to paste a .env file with real secrets?
The file is parsed in your browser and never uploaded. This tool is also marked sensitive: your input is never saved as a draft on this device, and creating a share link asks you to confirm first, because the link would contain the secrets.
When does # start a comment?
A line that starts with # is a comment. Inside an unquoted value, # starts a comment only after whitespace, as in Docker Compose, so PASSWORD=a#b keeps its # while REDIS_URL=redis://localhost:6379 # cache drops the comment. Inside quotes, # is always part of the value.
Are ${VAR} references expanded?
No. Values that refer to other variables, such as $HOME or ${DB_HOST}, are kept exactly as written and a warning tells you how many there are. Expansion depends on the program reading the file, so the tool doesn't guess.
Why are numbers still strings?
Environment variables are always strings, so that is the default. Set Values to "Numbers & booleans" to turn unquoted values like 3000 and true into JSON numbers and booleans. Quoted values always stay strings.
What happens with duplicate keys?
The last value wins, as with dotenv, and a warning lists both line numbers so you can remove the stale one.
Last updated