Skip to content
koducathome

JSON to .env Converter

Turn a JSON config object into a .env file — nested keys become DATABASE__HOST-style variables, with secrets detected and masked on request.

How to use this tool

Steps for using the JSON to .env.

  1. Paste a JSON object into the input, click Upload JSON, or click Sample. The .env output updates as you type.
  2. Choose how Nested keys are joined: DB__HOST (double underscore, read by ASP.NET Core and many config libraries), DB_HOST, or db.host for Spring-style loaders.
  3. Pick the key Case (UPPER_SNAKE splits camelCase, so databaseUrl becomes DATABASE_URL), how Arrays are written, when values are Quoted, and an optional Prefix such as MYAPP_.
  4. Toggle Section comments, Sort keys, export prefix, Skip null and Mask secrets as needed.
  5. Switch to Table to see every variable with its value and the JSON path it came from. Warnings list name collisions and invalid keys.
  6. Copy the result or Download it as .env. Everything runs in your browser — nothing is uploaded.

Example

Nested config to double-underscore variables

JSON
{
  "database": { "host": "db", "port": 5432 },
  "apiKey": "abc123",
  "features": ["search", "billing"]
}
.env (defaults)
# database
DATABASE__HOST=db
DATABASE__PORT=5432

API_KEY=abc123

# features
FEATURES__0=search
FEATURES__1=billing

Common use cases

  • Moving settings from appsettings.json or config.json into environment variables for Docker, Kubernetes or a PaaS.
  • Creating a .env file for local development from a JSON config checked into the repository.
  • Checking which variable names a framework will look for when it binds nested configuration from the environment.
  • Turning an API response or exported settings object into variables for a CI job.
  • Preparing a masked, shareable list of the configuration an app needs.

How JSON is flattened into environment variables

Environment variables are a flat list of NAME=value strings, while JSON nests objects and arrays. The converter walks the object depth-first and joins the keys on the way down: {"database": {"host": "db"}} becomes DATABASE__HOST=db. The double underscore is the most portable separator — ASP.NET Core maps __ back to its : section separator, and libraries such as convict, pydantic-settings (with env_nested_delimiter) and Spring Boot's relaxed binding can read nested names from the environment. A single underscore is easier to read but cannot be split back reliably when key names already contain underscores.

With UPPER_SNAKE, camelCase keys are split at their humps (maxRetries → MAX_RETRIES) and any character that is not a letter, digit or underscore becomes _, because POSIX shells and Docker env files only accept those characters. A name may not start with a digit, so such names get a leading underscore and a warning. If two JSON paths produce the same name — for example db_host and db.host — the converter keeps the last one, as dotenv does, and lists the collision so you can rename one.

Arrays have three modes. Indexed writes one variable per element (FEATURES__0, FEATURES__1) and recurses into objects inside arrays, which is what ASP.NET Core and most binders expect. Comma-joined suits simple lists that your code splits itself. JSON text keeps the whole array in one variable for code that calls JSON.parse. null becomes an empty value unless Skip null is on; numbers and booleans become their text form, since every environment variable is a string.

Values are quoted only when needed by default: plain words stay bare, values with spaces or # get single quotes, and values with newlines or single quotes get double quotes with \n escapes — the same rules as the Env Formatter. Variables whose names look like credentials (PASSWORD, SECRET, TOKEN, API_KEY…) or whose values are URLs with a password are flagged; Mask secrets shows only their first two characters so you can share the output safely.

Limitations

  • The top level must be a JSON object; a bare array has no names to build variables from.
  • Comments and trailing commas (JSONC) are not accepted — remove them first or use the JSON formatter to find them.
  • Single-underscore and dot separators cannot always be reversed back into the original nesting.
  • Secret detection is a name and URL heuristic, not a guarantee — review the output before sharing it.

Frequently asked questions

Why the double underscore?

A single underscore is ambiguous when keys already contain underscores (max_retries inside http). __ keeps the nesting recoverable, and ASP.NET Core, pydantic-settings and other libraries use it as their nested delimiter.

How do I turn the .env back into JSON?

Paste the output into the Env Formatter and choose JSON. Note that it produces a flat object; it does not rebuild the nesting.

Are my values uploaded anywhere?

No. Parsing and conversion run in this browser tab. Values are never sent to a server or to analytics.

Can I use the output with docker run or Kubernetes?

Yes — docker run --env-file .env reads it directly, and the Env Formatter converts it to -e flags, a Compose block, a Kubernetes env list, a ConfigMap or a Secret.