JSON to .env
Convert a JSON object to .env KEY=value lines, flattening nested keys and quoting values safely.
Paste or drop
Paste text below, or drop a file instead.
Choose an output
Convert a JSON object to .env KEY=value lines, flattening nested keys and quoting values safely.
Fine-tune
Optional — sensible defaults are already set.
About JSON to .env
This tool converts a JSON object into KEY=value lines for a .env file. Nested objects are flattened by joining keys with underscores, so {"db": {"host": "x"}} becomes DB_HOST=x, and values that contain spaces, quotes, # or $ are double-quoted and escaped.
When it helps
- Creating a .env file from a JSON config exported by a secrets manager or cloud console.
- Turning a nested settings object into flat environment variables for Docker or a twelve-factor app.
- Preparing variables to paste into a hosting provider's environment settings screen.
Tips
- Keys are uppercased by default, matching the usual convention for environment variables. Turn off "UPPERCASE keys" to keep the original case.
- Arrays are written as a JSON string, for example TAGS="[\"a\",\"b\"]". Your app will need to parse them.
- Characters that are not letters, digits or underscores in keys are replaced with _, since most shells do not accept them in variable names.
- The top-level value must be an object. A JSON array cannot be mapped to named variables.
Good to know
Quick answers about json to .env in your browser.
As an empty quoted string, for example API_KEY="". Environment variables have no null type, so code reading them should treat an empty value as unset if needed.
Yes. The output uses plain KEY=value lines with double quotes only where needed, which Docker Compose env_file and dotenv libraries both read. Check values containing escaped quotes or \n after loading, since some loaders do not expand escapes.
Yes. There is no sign-up, no watermark and no limit on how many files you process.
No. Files are read and processed locally in your browser, so they never leave your device.
Related tools
Part of the JSON, YAML & XML Tools collection.