JSON to .env — turn a config object into environment variables

Paste a JSON config object and get .env lines back, with camelCase keys turned into CONSTANT_CASE names, nested objects joined with an underscore and values quoted only when they need it.

Live demo · real result from this tool

.env

PORT=8080DATABASE_URL=postgres://app:secret@localhost:5432/appDEBUG=falseAPP_NAME="My App"APP_REGION=eu-west-1 

Processed on your device — nothing is uploaded.

How to use JSON to .env

  1. Paste a JSON object into JSON. The sample shows a typical app config.
  2. Optionally set a Key prefix, such as APP_, added to every variable name.
  3. Choose the Nested key separator: Single underscore (APP_NAME) or Double underscore (APP__NAME).
  4. Choose Quote values: When needed, Always or Never. Tick Prefix lines with export if the file will be loaded with source in a shell.
  5. Copy the result, or download it as .env.

What it does and when to use it

Many projects keep settings in a JSON file for local work but need the same values as environment variables in Docker, CI pipelines, Heroku-style hosts or a twelve-factor app. Typing each line by hand invites typos in names and broken quoting. This tool converts the whole object in one step and keeps the naming consistent.

Going the other way, the .env file generator helps you build a fresh file from a template, and the .env file sorter tidies an existing one. If your config is nested and you want to see the full key paths first, the JSON flattener shows them as dot-notation keys.

How it works

The object is flattened, so {"app": {"name": "My App"}} becomes the path app → name. Each part of the path is turned into CONSTANT_CASE: a lower-case letter or digit followed by a capital gets an underscore between them (databaseUrl → DATABASE_URL), any run of other characters becomes _, and the result is upper-cased. The parts are joined with your separator and the prefix is added. A name that would start with a digit gets a leading _, because most loaders and shells reject it otherwise.

Numbers and booleans are written as they appear, strings are written raw or quoted following your quote setting, and nested arrays are numbered.

Worked examples

The default config:

{"port": 8080, "databaseUrl": "postgres://app:pw@localhost:5432/app",
 "debug": false, "app": {"name": "My App", "region": "eu-west-1"}}
PORT=8080
DATABASE_URL=postgres://app:pw@localhost:5432/app
DEBUG=false
APP_NAME="My App"
APP_REGION=eu-west-1

Only My App is quoted, because it is the only value with a space.

With Key prefix APP_, double underscore and export ticked, {"redis": {"host": "cache", "port": 6379}, "apiKey": ""} gives:

export APP_REDIS__HOST=cache
export APP_REDIS__PORT=6379
export APP_API_KEY=

Limits and tips

  • Two JSON keys can map to the same name. appName and app.name both become APP_NAME; the tool writes both lines and warns. Loaders differ on which one wins, so rename one or use the double-underscore separator.
  • Never writes values with spaces unquoted, which breaks the file when a shell sources it.
  • The root must be an object; an array gives an error message.

Frequently asked questions

When does the tool add quotes?
With "When needed", a value is wrapped in double quotes if it contains a space, tab, line break,
Should I pick a single or double underscore for nested keys?
Match the library that will read the variables. ASP.NET Core configuration reads a double underscore as a section separator, and several Node and Python settings libraries offer the same option. Plain scripts usually use a single underscore. Both choices give the same names for keys that are not nested.
What happens to arrays and null?
Arrays are spread into numbered variables, so hosts ["a","b"] becomes HOSTS_0 and HOSTS_1. An empty array or object is written as [] or {}. A null value becomes an empty value.
Do double quotes stop $ from being expanded?
Not everywhere. Shells, Docker Compose and dotenv-expand still replace $NAME inside double quotes. If a password or token contains $, check how your loader handles it, and escape it or move the value to a secrets store if needed.
Is it safe to paste real secrets here?
The conversion runs in your browser and nothing is sent to a server. Even so, treat the output like any .env file and keep it out of version control.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close