JSON / YAML to .env Converter

Your data never leaves your browser

Turn a JSON or YAML config object into a valid .env file. Nested keys flattened automatically. 100% in your browser.

Input — JSON
Output — .env
Ctrl+Shift+CCopyCtrl+KClear

Share this tool

Found it useful? Help a fellow developer discover it.

https://developertoolkit.dev/tools/json-to-env

Convert in the other direction

Going the other way, reading a .env file as structured JSON or YAML?

Convert .env to JSON or YAML

Open .env to JSON / YAML Converter

Why convert JSON or YAML to .env?

Environment variables are flat strings. Configuration, as people actually write it, is nested. Every time you move config into a runtime that reads .env files, you hit that mismatch: a Docker Compose environment block, a Vercel or Netlify project, a Kubernetes secret, or a local dev setup that has to mirror what a JSON config service returns. Doing it by hand means inventing a naming scheme for nested keys and remembering which values need quoting. This converter flattens the structure using a double underscore between levels, which is the convention most config libraries already understand, and quotes only the values that would otherwise break parsing.

What the output looks like

How keys and values are written

  • ·Nested keys are joined with a double underscore, DB.HOST becomes DB__HOST
  • ·Values containing spaces or special characters are double-quoted
  • ·Numbers and booleans are written bare, as 5432 and false
  • ·An empty string becomes KEY= with nothing after the equals sign

Before you commit the file

  • ·A .env with real credentials belongs in .gitignore, never in the repo
  • ·Confirm your config library uses the same nested-key separator
  • ·Every value becomes a string once the process reads it
  • ·Commit a .env.example with the keys but not the secrets

How to convert JSON to a .env file

  1. Choose JSON or YAML. The format selector sets which one the tool expects as input. This page opens already pointed at the .env output direction.
  2. Paste your config object. Nested objects are fine. They are flattened automatically rather than rejected.
  3. Check the flattened key names. A nested path such as DB.HOST becomes DB__HOST. Confirm that matches what your config library expects.
  4. Copy into your .env. Paste the result into your file, or download it. Remember that a .env holding real secrets belongs in .gitignore.

Frequently Asked Questions

How do I convert JSON to a .env file?

Paste your JSON config object into the left panel. This page opens already set to output .env format, so dotenv lines appear on the right immediately with nested keys flattened. Copy them into your .env file or download the result.

How are nested objects turned into environment variables?

Environment variables are flat, so nesting has to be encoded in the name. Each level is joined with a double underscore, so {"DB": {"HOST": "localhost"}} becomes DB__HOST=localhost. The double underscore is the separator .NET, Spring Boot and many Node config libraries already recognize and map back to nested config.

Can I use YAML as the input instead of JSON?

Yes. Use the format selector to switch the input between JSON and YAML. This is handy for pulling a values.yaml or a Compose fragment into a local .env without a second conversion step.

Which values get quoted in the output?

Only the ones that need it. A value containing spaces or characters that would otherwise break parsing is wrapped in double quotes. Plain numbers, booleans, and simple strings are written bare, which keeps the file readable and matches what people write by hand.

What happens to booleans and numbers?

They are written without quotes, so 5432 stays 5432 and false stays false. Be aware that this is cosmetic: environment variables are strings at the operating system level, so your application will read the string "false", which is truthy in most languages. Parse these values explicitly rather than relying on the type surviving.

Is it safe to paste a config containing secrets?

Yes. The conversion runs entirely in your browser using client-side JavaScript. Your config is never sent to a server, never logged, and never leaves your device. Config files are exactly the kind of data that should never be pasted into a tool that uploads it, which is why this one does not.

How do I read an existing .env file as JSON or YAML?

Open the .env to JSON and YAML converter, a separate page written around that direction, covering comments, export prefixes, quoting and how nested keys are rebuilt into structure.

Should the generated .env be committed to git?

Not if it contains real credentials. Add .env to .gitignore and commit a .env.example alongside it that lists the same keys with placeholder values, so anyone setting the project up knows which variables are required without gaining access to the secrets.

Related Tools