.env to JSON
Convert .env files to JSON and back
About .env to JSON
.env to JSON converts a .env file into a JSON object, and a JSON object back into .env lines. It follows the rules of the dotenv library: an optional export, KEY=value or KEY: value, single quotes kept literally, double quotes turning \n into a line break, backticks, quoted values over several lines, and # comments outside quotes. By default, every value stays a string; options give typed numbers, true, false, and null, and expand ${VAR} references. Lines that are not variables are listed by number. Both directions run in your browser.
Example
A .env file with export, a comment, an inline comment, and a line that is not a variable, converted with both options unchecked; the line under the JSON is the note the page shows:
.env
export APP_NAME="My App" PORT=3000 # database DB_URL=postgres://localhost/app # local only GREETING="Hello\nWorld" RAW='$HOME stays' not a variable
JSON
{
"APP_NAME": "My App",
"PORT": "3000",
"DB_URL": "postgres://localhost/app",
"GREETING": "Hello\nWorld",
"RAW": "$HOME stays"
}
5 variables — line 7 is not KEY=value and was skippedHow to convert a .env file to JSON
- 1Paste your .env content, or a JSON object, into "Input".
- 2Check "Convert numbers, true/false, and null to JSON types" or "Expand ${VAR} references" if you need them.
- 3Click ".env to JSON", or "JSON to .env" for the other direction.
- 4Click "Copy", or "Download": env.json for JSON, variables.env for .env lines (rename it to .env).
Formats and limits
- Input
- .env text, or a JSON object
- Output
- JSON object with two-space indentation, or .env lines
- Repeated keys
- The last definition wins
Where your file is processed
Both directions run in your browser; the variables you paste, secrets included, are not uploaded, and the result is only shown on this page. If an error occurs, for example invalid JSON, its wording is reported to us with quoted text masked, with the tool name and browser version, so keep secrets out of key names.
Frequently asked questions
Does it expand ${OTHER_VAR} references?
Yes, when "Expand ${VAR} references" is checked: ${VAR}, ${VAR:-default}, and $VAR take the value of a variable defined earlier in the file, as dotenv-expand does, and \$ keeps a literal dollar sign. With the option checked, single-quoted values are expanded too.
Are numbers and booleans typed?
No, not by default, since .env values are text. Check "Convert numbers, true/false, and null to JSON types" and 3000 becomes a number and true, false, and null become JSON values, while 007 and 1.10 stay strings because a number would change them.
Are comments kept?
No. A line starting with #, or # after an unquoted value, is a comment and is dropped, so JSON to .env cannot restore it; a # inside quotes stays part of the value. A line that is neither a comment nor a variable is reported by its number.
Can JSON to .env handle nested objects?
Yes. A nested object or array is written as JSON text inside quotes, and each value gets the quoting that makes dotenv read it back unchanged; a value mixing ', ", \ and ` together is refused, since no .env quoting can hold it, and null gives an empty value. Keys may use only letters, digits, _, ., and -.