JSON to Env Converter
Convert a JSON object to .env KEY=VALUE format, with nested-object flattening and comment reinsertion. Client-side only.
Paste a JSON object and get .env lines that dotenv and similar loaders read at startup. Nested objects are flattened into dotted names such as db.host, arrays are written as one line of JSON text, and true, false, and numbers are written as plain text. A $comments map from Env to JSON becomes # lines above each variable again. Everything runs in your browser, so secrets in the JSON never leave your device.
About the JSON to Env Converter
Environment variables only hold flat strings, so turning JSON into a .env file is mostly a naming question. With flattening on, every nested path is joined with the separator: { "app": { "cache": { "ttl": 60 } } } becomes app.cache.ttl=60, and the case of each key is kept exactly as written in the JSON. A shell cannot use a name that contains a dot as a variable, so set the separator to an underscore (app_cache_ttl) when a shell script will source the file. With flattening off, nested objects are not expanded; each one is written as a single line of JSON text after the equals sign.
You May Also Need
How to convert JSON to .env
- 1
Paste a JSON object
Enter an object—not an array or a bare value—in the input panel, or click the flask icon to load a small flat sample with an API key and a port.
- 2
Choose how names are built
In Advanced options keep the dot for dotenv-style names like db.host, switch to an underscore for shell-safe names like db_host, or turn flattening off to keep nested objects as JSON text.
- 3
Click Convert
Each leaf value becomes one NAME=value line in the original key order, and $comments entries are written as # lines directly above the variable they describe. Values with a line break, leading or trailing spaces, or a # are wrapped in quotes (a line break is written as \n), so converting back to JSON returns them unchanged.
- 4
Save the .env file
Copy the text or download a .env file, keep it out of version control if it holds credentials, and use the switch-direction icon to parse it back into JSON.
References
- The Twelve-Factor App — Config
The methodology behind storing configuration as environment variables, which this converter's output format follows.
- dotenv (motdotla) — README
The reference implementation for .env file syntax, describing how KEY=VALUE pairs and comments are conventionally written.
- RFC 8259 — The JSON Data Interchange Format
The IETF specification for the JSON input format this tool parses.
Related developer tools
Env to JSON
Convert a .env file into JSON, with type inference, nested keys, and comment preservation.
JSON to Properties
Convert a JSON object into Java .properties format, the equivalent flow for properties files.
JSON Formatter
Paste raw JSON and instantly get a formatted, syntax-highlighted, validated view before converting it.
YAML to JSON
Convert between YAML and JSON configuration formats.
JSON to Env FAQ
- Are variable names converted to uppercase?
- No. Keys keep the exact case from your JSON, so { "db": { "host": "x" } } becomes db.host=x. Environment variable names are case-sensitive on Linux and macOS, so write the JSON keys in the case your application reads.
- Can a shell script source the generated .env file?
- Only when every name is a valid shell identifier: letters, digits, and underscores, not starting with a digit. Dotted names such as db.host load fine with dotenv for Node.js, but a shell will not treat them as assignments, so choose the underscore separator for files you plan to source.
- What happens to arrays and nested objects?
- With flattening on, nested objects become separate dotted variables, while an array is written as one line of JSON text, for example tags=["a","b"]. With flattening off, nested objects are kept whole as JSON text as well.
- How are booleans and numbers written?
- As plain text—true, false, or the number itself—because .env files have no types. Env to JSON reads them back as real booleans and numbers when type inference is on.
- Does JSON to Env write comments?
- Yes. If the JSON has a $comments object, such as the one Env to JSON produces, each entry becomes a # line above the matching variable. Set Comments to "Ignore" in Advanced options to output bare NAME=value lines.
- Is my JSON uploaded when I convert it?
- No. Conversion runs locally in your browser, which matters because .env files usually hold API keys and database passwords.
- Why do I get an invalid variable name error?
- A name cannot be read back from a .env file if it is empty or contains spaces, =, :, #, quotes, or a backslash, so the converter stops and shows that key instead of writing a broken line. Rename the key in the JSON, or pick another separator if the separator added the character.