JSON to .env converter
Config often starts life as a JSON object but has to be deployed as a .env
file of environment variables. This tool converts a JSON configuration
object into dotenv KEY=value lines, handling the flattening and quoting rules
so the result drops straight into a .env file.
How it works
The converter flattens the object to a single level and formats each leaf as a line:
- Nested objects are flattened with underscores, so
{"API": {"KEY": "x"}}becomesAPI_KEY=x. - Arrays and remaining objects are serialised back to compact JSON and quoted.
- Quoting: a value is wrapped in double quotes whenever it contains
whitespace, a
#, an=, a quote or a newline, or is empty. Plain numbers and booleans are written unquoted, matching how dotenv parsers expect values.
Example
This JSON:
{ "API": { "KEY": "ab cd" }, "PORT": 3000, "DEBUG": true }
converts to:
API_KEY="ab cd"
PORT=3000
DEBUG=true
API.KEY flattened to API_KEY, the value with a space was quoted, and the
number and boolean were left unquoted.
Everything runs in your browser — your configuration never leaves your device.
When you need this converter
The most common workflow is when a cloud platform, SDK, or configuration tool exports settings as JSON (for example a service account file, a Pulumi config dump, or a Terraform output) and your runtime environment reads from a .env file. Rather than manually reformatting each key and handling quoting rules yourself, paste the JSON here and copy the ready-to-use output.
Other common scenarios:
- Seeding a new project. You have a JSON object of development defaults you want to distribute to the team as a
.env.examplefile. - CI environment setup. Your CI pipeline receives secrets as JSON from a vault integration but needs to write them as environment variable exports for subsequent steps.
- Docker Compose. Docker Compose accepts
env_filedirectives pointing to dotenv files; converting from JSON makes it easy to populate those files from JSON-based secrets managers.
Quoting rules in detail
The .env format is not fully standardised — different parsers (Python python-dotenv, Node dotenv, Docker, Bash) have slightly different quoting behaviour. This tool follows the conventions that work across the most common parsers:
| Value type | Output | Example |
|---|---|---|
| Plain string | Unquoted if safe | NAME=alice |
| String with spaces | Double-quoted | NAME="alice smith" |
String with # or = | Double-quoted | EXPR="a=b" |
| Empty string | Double-quoted empty | EMPTY="" |
| Number | Unquoted | PORT=3000 |
| Boolean | Unquoted | DEBUG=true |
| Array or object | Compact JSON, double-quoted | TAGS="[\"a\",\"b\"]" |