JSON to .env
Convert JSON objects to .env file format — flatten keys to KEY=VALUE pairs.
or drop a file here
Quote values
.env Output
JSON to .env Converter
This tool converts a JSON object into a .env file, ready to paste into your project. Keys are uppercased automatically. Nested objects are flattened using underscore separators (e.g. { db: { host: 'x' } } becomes DB_HOST=x). An optional key prefix lets you namespace all variables (e.g. APP turns NAME into APP_NAME). The quote mode controls whether values are wrapped in double quotes. Everything runs in your browser — no data is uploaded.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Producing environment variables from a JSON config for a container or a platform.
- Flattening a config object into the names a twelve-factor app expects.
- Generating a local `.env` from a checked-in JSON template.
- Converting settings for a deployment target that only reads environment variables.
- Comparing a JSON config against an existing environment file.
Frequently Asked Questions
- Why is the pasted JSON kept out of the shared link?
- Because config JSON carries the same credentials a .env file does — this is one of four converters where the input is held in memory only, never written into the URL. The options stay URL-bound, so a shared link reproduces your settings without the payload.
- How are nested objects handled?
- They flatten into underscore-joined uppercase keys, so {"db":{"host":"x"}} becomes DB_HOST=x. Environment variables are a flat string map with no nesting, so this is the only faithful mapping — and it is why a deeply nested config produces some very long names.
- When does a value need quoting?
- Whenever it is empty or contains whitespace, #, a quote, a backslash or an equals sign — anything a shell or dotenv parser would otherwise misread. Auto mode quotes exactly those and leaves the rest bare, which keeps the file readable; Always is safer for machine consumption.
- What happens to arrays?
- They collapse to a comma-joined string, because environment variables hold text and nothing else. That is lossy in one specific way: an element containing a comma becomes indistinguishable from two elements, so restructure those into numbered keys before converting.
- Do types survive the round trip?
- No, and they cannot. Every value becomes a string, so true, 5432 and "5432" are identical once written — the receiving application decides what they mean. That is the fundamental difference between JSON and a .env file, not a limitation of the conversion.
Common errors and gotchas
- Committing the result, which usually contains secrets and is gitignored for exactly that reason.
- Producing names that are not valid identifiers, such as ones containing a dash or starting with a digit.
- Losing types, since every environment variable is a string however numeric it looked.
- Flattening nested objects with no agreed separator, so the consumer has to guess the convention.
- Emitting a value containing newlines, which most environment file parsers cannot carry.
Related Converters tools
JSON to YAML
Convert JSON into clean, readable YAML instantly.
YAML to JSON
Convert YAML configuration into valid JSON.
JSON to XML
Convert JSON structures into nested XML markup.
HWB to HEX Converter
Convert an HWB color to HEX.
JSON to SQL
Turn a JSON array of objects into SQL INSERT statements.
CSV to XML
Convert CSV rows into structured XML records.
XML to CSV
Flatten repeated XML records into CSV rows.
INI to JSON
Parse INI config sections and keys into JSON.