How to use JSON to .env
- Paste a JSON object into JSON. The sample shows a typical app config.
- Optionally set a Key prefix, such as
APP_, added to every variable name. - Choose the Nested key separator: Single underscore (APP_NAME) or Double underscore (APP__NAME).
- Choose Quote values: When needed, Always or Never. Tick Prefix lines with export if the file will be loaded with
sourcein a shell. - 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.
appNameandapp.nameboth becomeAPP_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?
Should I pick a single or double underscore for nested keys?
What happens to arrays and null?
Do double quotes stop $ from being expanded?
Is it safe to paste real secrets here?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.