FormatterHQ

JSON to .env Converter

Turn a JSON config object into a .env file: nested keys become APP__NAME style variables, arrays get numbered keys, and values with spaces or symbols are quoted safely.

Input JSON
Output SHELL
Ready.

How to use the JSON to .env Converter

  1. Paste a JSON object into the input editor.
  2. Set the Nested key separator (__ by default).
  3. Choose whether to force UPPERCASE keys and whether to Prefix with export.
  4. Click Convert and save the output as .env.

Generate a .env file with the JSON to env converter

The JSON to env converter flattens a JSON object into dotenv lines. Each leaf value becomes one KEY=value line, nested object keys are joined with a separator, and values that would confuse a dotenv parser are wrapped in double quotes with the necessary escapes. It is useful when a secrets manager, CI system or teammate hands you JSON but your app reads environment variables.

Example

Input:

{
  "app": { "name": "Acme Shop", "debug": false, "port": 8080 },
  "redis-cache": { "url": "redis://cache:6379" },
  "features": ["search", "checkout"],
  "secret": "p@ss$word"
}

Output with the defaults:

APP__NAME="Acme Shop"
APP__DEBUG=false
APP__PORT=8080
REDIS_CACHE__URL=redis://cache:6379
FEATURES__0=search
FEATURES__1=checkout
SECRET="p@ss\$word"

Options explained

  • Nested key separator: __ matches ASP.NET Core and the nesting option in .env to JSON, so the two tools round-trip. Use _ for a flatter look, knowing that it can no longer be split back unambiguously.
  • UPPERCASE keys: on by default, following the usual convention for environment variables. Turn it off to keep the original casing, for example db__host.
  • Prefix with export: writes export KEY=value, so the file can be loaded with source .env in a shell and the variables reach child processes.

How values are written

  • Plain words, numbers and booleans are written as they are.
  • Values containing spaces, #, quotes, =, backslashes, backticks or $ are double-quoted. $ is escaped as \$ so it is not treated as a variable reference.
  • Line breaks become \n inside double quotes, keeping each variable on one line.
  • null becomes an empty value (KEY=) and an empty string becomes KEY="".

How different loaders read the file

The .env format has no single standard, so check how the tool that reads your file treats quotes before you rely on them:

LoaderSurrounding quotesNotes
source .env in bash (with the export option)RemovedNormal shell rules, so $ must stay escaped
Docker Compose env_fileRemovedSupports ${VAR} interpolation
docker run --env-fileKept as part of the valueEvery line is taken literally, so "Acme Shop" includes the quotes
Node.js --env-file and the dotenv packageRemovedNo variable expansion unless you add dotenv-expand

If a value comes out with stray quotes or backslashes, the loader is the cause, not the conversion. For docker run, keep such values simple or pass them with -e instead.

Edge cases

  • Invalid characters in keys: anything other than letters, digits and underscores is replaced with _, so redis-cache becomes REDIS_CACHE.
  • Keys starting with a digit get a leading underscore, because shells reject variable names such as 2FA_ENABLED.
  • Arrays are expanded into numbered keys (FEATURES__0, FEATURES__1). If your app expects a single comma-separated value, join the array in the JSON first.
  • Empty objects and arrays are written as JSON text, such as EXTRA={}.

For Kubernetes or Docker Compose files that expect structured config rather than flat variables, convert the JSON with JSON to YAML instead.

Privacy

The conversion happens locally in your browser, so API keys and passwords in your JSON are never uploaded.

Frequently asked questions

How are nested JSON objects converted to environment variables?
Their keys are joined with the Nested key separator, which is __ by default. {"db": {"host": "x"}} becomes DB__HOST=x, which frameworks like ASP.NET Core map back to nested settings.
Why is there a backslash before $ in my output?
Many dotenv loaders expand $NAME inside double-quoted values. Escaping it as \$ keeps the dollar sign literal, so a password like p@ss$word loads unchanged.
Can I keep lowercase keys?
Yes. Untick UPPERCASE keys and the original casing is kept. Characters that are not letters, digits or underscores are still replaced with underscores.
What happens to arrays?
Each element gets its own numbered key, such as FEATURES__0 and FEATURES__1. Nested objects inside arrays continue the path, for example ITEMS__0__SKU.

Last updated September 26, 2026

Guides

Related tools