Skip to content

Menu

JSON to .env

Convert JSON to .env KEY=value format

Runs entirely in your browserConvertersFree, no sign-up
Loading tool

01What is JSON to .env?

Config often starts life as JSON, but Docker Compose, most hosting platforms and the dotenv package want flat KEY=value lines. This converter does that flattening for you. Paste a JSON object and every leaf value becomes one environment variable. Names are built from the path to each value. Nested keys are joined with underscores, so database.host becomes DATABASE_HOST. camelCase is split before uppercasing, which turns secretKey into SECRET_KEY and maxRetries into MAX_RETRIES. Runs of capitals are handled too: apiURL gives API_URL and HTTPServer gives HTTP_SERVER. POSIX only allows letters, digits and underscores in variable names, so dots, dashes and spaces become underscores, and a name that would start with a digit gets a leading underscore. Values follow simple rules. Numbers and booleans are written as text. null becomes an empty value. Arrays of plain values are joined with commas, so [1, null, 3] gives 1,,3. Arrays that hold objects are written as JSON text instead, because there is no sensible flat form for them. Quoting is the part people usually get wrong, so we followed the dotenv package's own parser. dotenv has no backslash escapes except \n and \r inside double quotes. A value with a #, a quote, a $, a line break, or leading or trailing spaces gets quoted. Single quotes are tried first, since they also stop dotenv-expand from treating $HOME as a variable. If the value contains a single quote, double quotes are used. If it has both, backticks are used. A value mixing all three quote characters can't be written for dotenv at all, and the tool tells you so instead of producing a broken line. Multi-line values such as PEM keys keep their real line breaks inside the quotes. A quick example: {"greeting": "it's $HOME"} becomes GREETING="it's $HOME". Double quotes are used because the value holds an apostrophe. dotenv will read that back exactly, though dotenv-expand would still expand $HOME in a double-quoted value. The output adds a blank line whenever the first word of the key changes, so DATABASE_* and REDIS_* land in separate blocks. That is purely cosmetic. The top level must be an object. Arrays and plain values are rejected with an error. Other .env readers, such as shell source or some dashboards, have their own quoting rules, so check output with multi-line or quoted values against your target. The conversion is plain JavaScript in the page, so your secrets never leave the tab.

Backend and DevOps engineers who keep config in JSON but deploy apps that read their settings from environment variables. The tool runs entirely in your browser, so your data never leaves your device.

02How to use JSON to .env

  1. Paste a JSON object into JSON Input, or load the API config, Simple flat config or Deeply nested example.
  2. Read the converted lines in .env Output as you type.
  3. If an error appears below the panels, fix the JSON. The top level must be an object, not an array.
  4. Click Copy Output and save the result as .env, or paste it into your host's settings.
  5. Use Reset to clear the input and start again.

03Worked examples

Input: {"database":{"host":"localhost","port":5432},"redis":{"url":"redis://localhost:6379"}}
Result: DATABASE_HOST=localhost DATABASE_PORT=5432 REDIS_URL=redis://localhost:6379
Nested keys are joined with underscores. A blank line separates the DATABASE and REDIS groups.
Input: {"apiURL":"https://x.io","HTTPServer":{"port":80},"1st":"a","log-level":"warn"}
Result: API_URL=https://x.io HTTP_SERVER_PORT=80 _1ST=a LOG_LEVEL=warn
Acronyms split cleanly, the dash becomes an underscore and a leading digit gets an underscore prefix.
Input: {"greeting":"it's $HOME","pem":"line1\nline2","pad":" x "}
Result: GREETING="it's $HOME" PEM='line1 line2' PAD=' x '
The apostrophe forces double quotes. The line break stays real inside single quotes, and surrounding spaces are kept by quoting.
Input: {"hosts":[{"name":"a"}],"ids":[1,null,3]}
Result: HOSTS='[{"name":"a"}]' IDS=1,,3
An array of objects is written as JSON text. A plain array is comma-joined, and null leaves an empty slot.
Input: {"pw":"p\"q'r"}
Result: PW=`p"q'r`
With both single and double quotes in the value, backticks are the only quote dotenv can read back unchanged.
Input: {"bad":"a'b\"c`d"}
Result: Error: The value "a'b\"c`d" mixes ', " and ` quotes (or ends in a backslash), which dotenv cannot represent.
All three quote characters in one value cannot be written for dotenv, so the tool refuses rather than emitting a broken line.

04Common use cases

  • Turning a config.json or appsettings.json into environment variables for a Docker Compose env_file
  • Moving secrets from a JSON credentials file into .env.local for a Next.js or Vite project
  • Preparing KEY=value lines to paste into the environment settings of Vercel, Netlify, Railway or Render
  • Converting JSON output from Terraform or a CI job into dotenv format for a local script
  • Storing a multi-line PEM private key in a .env file without breaking the dotenv parser
  • Checking what variable names a nested config will produce before writing the code that reads them

05Tips

  • Arrays of objects come out as JSON text such as '[{"name":"a"}]', so your app has to JSON.parse that variable when it reads it.
  • A null inside an array leaves an empty slot: [1,null,3] becomes 1,,3. Split on commas carefully if empty entries matter.
  • Values with $ are single-quoted when possible so dotenv-expand leaves them alone. If the value also has an apostrophe it falls back to double quotes, and expansion can happen.
  • Two JSON paths can map to the same name, for example a.b and a_b both become A_B. Scan the output for duplicates before you rely on it.
  • Commit a .env.example with the same keys and blank values, and keep the real .env in .gitignore.

06Related concepts

Environment variables, dotenv, Twelve-factor app, UPPER_SNAKE_CASE, Configuration management.

Frequently Asked Questions

What is JSON to .env?

JSON to .env is a free, browser-based developer tool on AIDToolStack. Convert JSON to .env KEY=value format It requires no installation or sign-up and works entirely in your browser.

Is JSON to .env free to use?

Yes. No sign-up, no fees and no usage cap.

Does JSON to .env store my data?

No. It runs in your browser; nothing is uploaded.

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe