Convert .env to JSON and Back
dotenv to JSON reads the KEY=VALUE lines of a .env file and turns them into a pretty two-space JSON object, or takes a flat JSON object and writes it back out as .env lines. Comments, blank lines, an optional export prefix, surrounding quotes, and equals signs inside values are all handled the way a dotenv loader would. Every value is treated as text, matching how environment variables actually behave.
How to convert .env to JSON
- Choose a direction with the toggle: '.env to JSON' or 'JSON to .env'.
- Paste your .env contents (or your JSON) into the input box on the left.
- Watch the converted result appear on the right as you type.
- If your JSON is malformed the error message shows next to the output label, so fix the input and it clears.
- Click Copy to grab the finished output.
Examples
.env to JSON: export prefix stripped, quotes removed, equals kept
# database export DB_HOST=localhost DB_URL="postgres://a=b@host"
{
"DB_HOST": "localhost",
"DB_URL": "postgres://a=b@host"
}.env to JSON: single quotes stripped and numbers stay strings
NODE_ENV=production DEBUG='true' RETRIES=5
{
"NODE_ENV": "production",
"DEBUG": "true",
"RETRIES": "5"
}JSON to .env: values with spaces get quoted automatically
{
"PORT": "3000",
"GREETING": "hello world"
}PORT=3000 GREETING="hello world"
Frequently asked questions
Does it keep equals signs inside values?
Yes. Only the first equals sign on a line splits the key from the value, so connection strings, JWTs, and tokens that contain an = character keep everything after that first split intact.
Are comments and blank lines ignored?
Yes. A line that is empty or begins with # after trimming is skipped, so the JSON contains only real variables. Comments are not carried into the output, and they are not written back when you convert JSON to .env.
What happens to the export prefix and quotes?
A single leading 'export ' is removed so shell-sourced files convert cleanly, and one matching pair of surrounding single or double quotes is stripped from each value. Inner quotes and spaces inside a quoted value are preserved.
Will every value be a string?
Yes. Environment variables are strings at the operating system level, so 5, true, and null all become quoted strings such as "5" and "true" in the JSON. Your application is responsible for casting them to numbers or booleans.
How does JSON to .env decide when to quote a value?
A value is wrapped in double quotes only when it needs protecting: when it is empty or contains a space, a #, or a quote character. Any inner double quotes are backslash-escaped. Plain values like 3000 are written without quotes.
Are multi-line values supported?
No. The parser treats every newline as the end of a pair, so a value that wraps across several lines will not be read as one value. Keep each KEY=VALUE on a single line.
What if two lines share the same key?
The last occurrence wins. Each pair is written into the same map, so a later DB_HOST overwrites an earlier one, just as re-exporting a variable in a shell would.
Can it convert nested JSON back to .env?
Only flat objects convert cleanly. The JSON to .env direction expects a single object of key/value pairs; a top-level array or non-object is rejected, and a nested object value is stringified rather than expanded into dotted keys.
Is my data private?
Yes. The conversion runs entirely in your browser, so secrets in your .env file are never uploaded to a server. Still, treat any file that holds credentials with care after you copy the result.
Learn more
- The .env format and how it maps to JSON
How dotenv files store configuration, the syntax rules this converter follows, and why every value ends up as a string in JSON.
Related tools
JSON Formatter
Format, validate and minify JSON online. Pretty-print with custom indentation, sort keys and catch syntax errors. Runs in your browser.
CSV to JSON
Convert CSV to JSON online. Turn spreadsheet rows into clean JSON objects or arrays, with smart number and boolean typing. Free tier plus API.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
ASCII Table
Full ASCII table for all 128 codes with decimal, hex, octal and binary values, character names and descriptions. Search by code, hex or character.
Aspect Ratio Box Generator
Generate CSS for a responsive aspect-ratio container. Use the modern aspect-ratio property or the padding-top fallback, then copy the ready code.
Aspect Ratio Calculator
Calculate aspect ratios fast. Enter a ratio like 16:9 and one dimension to get the other, or enter width and height to simplify the ratio.