JSON to .env

Flatten JSON into a ready-to-use dotenv file.

Runs in your browser Instant No sign-up
Keys
Nested keys
JSON input
.env
Reverse

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How to use the JSON to .env converter

  1. Paste a JSON object into the left pane. The .env file appears as you type.
  2. Keys: UPPER_SNAKE (the default) or As written.
  3. Nested keys: join levels with _ or with __.
  4. Under More options: how Arrays are written, and whether each line gets an export prefix so the file can be sourced in a shell.
  5. Copy or Download the result as .env.

Example

{
  "nodeEnv": "production",
  "port": 8080,
  "database": { "host": "db.internal", "port": 5432, "user": "app" },
  "allowedOrigins": ["https://tidypane.dev", "https://www.tidypane.dev"],
  "greeting": "Hello world"
}

becomes

NODE_ENV=production
PORT=8080
DATABASE_HOST=db.internal
DATABASE_PORT=5432
DATABASE_USER=app
ALLOWED_ORIGINS=https://tidypane.dev,https://www.tidypane.dev
GREETING="Hello world"

Details that matter

  • Every variable name must be unique. If two JSON paths flatten to the same name, the tool reports both instead of keeping only one.
  • Names must be valid. With As written keys, a key containing spaces or other characters a .env file can’t hold is rejected with an explanation.
  • null becomes an empty value (KEY=), and an empty object or array also produces an empty value, so the key still exists.
  • Quoting is minimal but safe, so # in a password or a value with spaces is never cut short when the file is read back.

When to use it

  • Turning app settings into environment variables for Docker, Docker Compose, Kubernetes or a hosting dashboard. To turn a docker run command into a Compose file, use Docker Run to Compose.
  • Generating .env.example files from a JSON config, then replacing the secrets with placeholders.
  • Twelve-factor apps that read configuration only from the environment.

Common pitfalls

Environment variables are flat strings, so some structure is always lost: numbers and booleans become text, and the program reading the variables has to convert them back. Keep that in mind for values like "port": "08" where leading zeros matter. Very long JSON arrays or objects written as JSON text can also hit length limits in some hosting dashboards, so the one-key-per-item option is often the better choice there. Finally, commit only an .env.example without real secrets to version control, and keep the real .env out of the repository with .gitignore.

Need the reverse? Click Reverse or open .env to JSON. For other targets such as YAML or TOML, use the Data Format Converter.

Frequently asked questions

How are nested objects turned into variable names?

Each level of nesting is joined with an underscore and converted to UPPER_SNAKE_CASE, so {"database": {"host": "db"}} becomes DATABASE_HOST=db and camelCase keys like allowedOrigins become ALLOWED_ORIGINS. Choose "a__b" under Nested keys to get DATABASE__HOST instead, the convention .NET and several Node.js config libraries use to read nested settings.

Which values get quoted?

Only values that a dotenv parser would otherwise misread: values containing spaces, #, quotes, backslashes, $ or =, and values with leading or trailing spaces. Newlines and tabs are written as \n and \t inside double quotes. Simple values such as URLs and numbers stay unquoted.

What happens to arrays?

By default arrays of plain values become one comma-separated value, such as ALLOWED_ORIGINS=a,b. Under More options you can write them as JSON text, or give each item its own variable (ITEMS_0, ITEMS_1). Arrays that contain objects are always written as JSON text.

What if two keys produce the same variable name?

The tool stops with an error naming both JSON paths, because one would silently overwrite the other. For example db_host and db.host both become DB_HOST; rename one of them or switch Nested keys to a__b.

Is it safe to paste real secrets?

Conversion runs in your browser and nothing is uploaded. The tool is marked sensitive, so your input is never saved as a draft, and creating a share link asks you to confirm first.

Last updated