JSON to .env

Flattens a JSON config into .env lines, joining nested keys with underscores in upper case, so database.host becomes DATABASE_HOST.

Use the tool

Why this tool exists

Configuration often starts life as a JSON file and then has to become environment variables for Docker, a CI job or a hosting dashboard. Retyping nested keys as flat names is easy to get wrong, and values with spaces or a dollar sign need quoting rules that vary between loaders. This tool walks the JSON, builds the names for you and quotes values that need it. You can add a prefix, change the separator, switch off upper-casing and choose how arrays are written. It runs locally, which is useful because config files tend to hold passwords and tokens you would rather not paste into a stranger's server.

How to use it

  1. Paste a JSON object into the input box. The top level has to be an object.
  2. Set an optional prefix and separator, and choose upper-case keys or not.
  3. Pick how arrays are written: indexed keys, one comma-separated value or a JSON string, then copy the result.

Frequently asked questions

How are nested keys named?

The path is joined with your separator (underscore by default), characters outside A-Z, a-z, 0-9 and underscore are replaced by underscores, and the result is upper-cased unless you turn that off. So app.port becomes APP_PORT.

What happens to arrays?

Indexed mode gives KEY_0, KEY_1 and so on. Comma mode joins simple values into one line. JSON mode stores the whole array as a JSON string. Comma mode falls back to JSON when an array holds objects.

When are values quoted?

Empty values and anything containing whitespace, #, quotes, $, backticks, backslashes or = are wrapped in double quotes with the special characters escaped. Plain values stay bare. null becomes an empty value.

Will every .env loader read the output?

Most will, but quoting rules differ slightly between dotenv, Docker and shells. Test the file with the loader you actually use before relying on it.