JSON to .env Converter

Turn a JSON config object into dotenv key=value lines — in your browser.

Free online JSON to .env converter. Flatten a JSON object into dotenv KEY=value lines, with nested keys joined by underscores and values quoted when needed. Privacy-first: your config never leaves your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How are nested objects handled?

Nested objects are flattened into a single level using underscores, so {"API": {"KEY": "x"}} becomes API_KEY=x. Arrays and remaining objects are serialised back to compact JSON and quoted.

JSON to .env converter

Config often starts life as a JSON object but has to be deployed as a .env file of environment variables. This tool converts a JSON configuration object into dotenv KEY=value lines, handling the flattening and quoting rules so the result drops straight into a .env file.

How it works

The converter flattens the object to a single level and formats each leaf as a line:

  • Nested objects are flattened with underscores, so {"API": {"KEY": "x"}} becomes API_KEY=x.
  • Arrays and remaining objects are serialised back to compact JSON and quoted.
  • Quoting: a value is wrapped in double quotes whenever it contains whitespace, a #, an =, a quote or a newline, or is empty. Plain numbers and booleans are written unquoted, matching how dotenv parsers expect values.

Example

This JSON:

{ "API": { "KEY": "ab cd" }, "PORT": 3000, "DEBUG": true }

converts to:

API_KEY="ab cd"
PORT=3000
DEBUG=true

API.KEY flattened to API_KEY, the value with a space was quoted, and the number and boolean were left unquoted.

Everything runs in your browser — your configuration never leaves your device.

When you need this converter

The most common workflow is when a cloud platform, SDK, or configuration tool exports settings as JSON (for example a service account file, a Pulumi config dump, or a Terraform output) and your runtime environment reads from a .env file. Rather than manually reformatting each key and handling quoting rules yourself, paste the JSON here and copy the ready-to-use output.

Other common scenarios:

  • Seeding a new project. You have a JSON object of development defaults you want to distribute to the team as a .env.example file.
  • CI environment setup. Your CI pipeline receives secrets as JSON from a vault integration but needs to write them as environment variable exports for subsequent steps.
  • Docker Compose. Docker Compose accepts env_file directives pointing to dotenv files; converting from JSON makes it easy to populate those files from JSON-based secrets managers.

Quoting rules in detail

The .env format is not fully standardised — different parsers (Python python-dotenv, Node dotenv, Docker, Bash) have slightly different quoting behaviour. This tool follows the conventions that work across the most common parsers:

Value typeOutputExample
Plain stringUnquoted if safeNAME=alice
String with spacesDouble-quotedNAME="alice smith"
String with # or =Double-quotedEXPR="a=b"
Empty stringDouble-quoted emptyEMPTY=""
NumberUnquotedPORT=3000
BooleanUnquotedDEBUG=true
Array or objectCompact JSON, double-quotedTAGS="[\"a\",\"b\"]"