Skip to content

JSON to .env Converter

Paste a JSON object, get a .env file instantly. Generate dotenv from config locally — your keys and secrets never leave your browser. 100% private, no upload.

No Tracking Runs in Browser Free
Options · keep keys · no export
0 chars
.env Output
0 lines
Reviewed for object-only input handling, round-trip-safe quoting, nested-value flattening, and key normalization — Go Tools Engineering Team · Jun 12, 2026

What is a .env File?

A .env file (dotenv file) is a plain-text list of KEY=VALUE pairs that holds environment configuration and secrets outside your source code. It is the de facto standard for Node.js, Vite, Next.js, Python, Ruby and Docker Compose — the dotenv library loads the file and injects each pair into the process environment. Because it commonly stores database passwords, API keys and access tokens, a .env file is treated as sensitive and kept out of version control.

Generating a .env file from JSON is the reverse of the common parse-config task: you already have configuration as a JSON object — from an API response, a config export, a secrets-manager dump, or a script that builds settings programmatically — and you need a .env file to drop into a project or hand to a container. This converter walks the top-level keys of your JSON object and writes one correctly quoted KEY=VALUE line per property.

This tool is built around a few deliberate decisions:

**1. Round-trip-safe quoting.** Numbers and booleans are written bare, null becomes an empty value, and any string that contains a space, newline, # or quote is automatically double-quoted and escaped. The result parses back cleanly through dotenv and through the companion .env to JSON Converter, so a value never changes meaning on the round trip.

**2. Honest handling of nesting.** A .env file is flat by definition. Rather than silently dropping nested data, the tool serializes each nested object or array to a compact JSON string and warns you which keys were flattened, so you can decide whether .env is really the right target.

**3. Optional key normalization.** Keys are kept verbatim by default to avoid losing information. Turn on Normalize keys to convert camelCase or kebab-case into the UPPER_SNAKE_CASE convention environment variables use, with a warning for any key that still cannot form a valid name.

**4. 100% browser-based privacy.** The JSON you paste — usually the very credentials you are about to write into a .env — never leaves the browser. No upload, no server round-trip, no logging; verify zero network requests in the DevTools Network tab.

Before converting, you can validate or pretty-print the JSON with the JSON Formatter, or unescape a JSON string with JSON Escape. If your configuration is better expressed with structure, JSON to YAML preserves nesting that a flat .env cannot.

// Generate .env lines from a JSON object in Node.js
const config = {
  DATABASE_URL: 'postgres://user:pass@localhost:5432/mydb',
  PORT: 8080,
  DEBUG: true,
  NOTE: 'value with spaces',
};

const needsQuotes = (s) => /[\s#"'\n]/.test(s);

const env = Object.entries(config)
  .map(([key, value]) => {
    if (typeof value === 'string') {
      return needsQuotes(value)
        ? `${key}=${JSON.stringify(value)}`
        : `${key}=${value}`;
    }
    return `${key}=${value ?? ''}`; // null -> empty value
  })
  .join('\n');

console.log(env);
// DATABASE_URL=postgres://user:pass@localhost:5432/mydb
// PORT=8080
// DEBUG=true
// NOTE="value with spaces"

Key Features

Round-Trip-Safe Quoting

Numbers and booleans are written bare, null becomes an empty value, and strings with spaces, newlines, # or quotes are automatically double-quoted and escaped so they parse back cleanly through dotenv.

Honest Nesting Handling

Nested objects and arrays can't exist in a flat .env, so each is serialized to a compact JSON string and a warning lists exactly which keys were flattened — never a silent change.

Optional Key Normalization

Keep keys verbatim by default — with a warning for any key that is not a valid env name — or turn on Normalize keys to convert camelCase and kebab-case into the UPPER_SNAKE_CASE convention environment variables use.

Optional export Prefix

Prepend export to every line so the generated .env file can be sourced directly in a shell, matching the style of CI and deploy scripts.

Live Conversion

.env output updates instantly as you type or paste JSON. Large inputs (over 200KB) switch to manual mode with a Convert button to keep the browser responsive.

100% Browser-Based Privacy

All conversion runs locally in your browser. The JSON you paste — API keys, credentials, tokens — is never uploaded, never logged and never stored on any server.

Examples

Config object to .env

{
  "DATABASE_URL": "postgres://user:pass@localhost:5432/mydb",
  "PORT": 8080,
  "DEBUG": true,
  "LOG_LEVEL": "info",
  "API_KEY": "sk_live_abc123"
}
DATABASE_URL=postgres://user:pass@localhost:5432/mydb
PORT=8080
DEBUG=true
LOG_LEVEL=info
API_KEY=sk_live_abc123

A flat JSON config object becomes a clean .env file. Numbers and booleans are written without quotes; plain strings are written as-is. Ready to save as .env and load with dotenv.

Values that need quoting

{
  "GREETING": "Hello, World",
  "MOTD": "line one\nline two",
  "COLOR": "#ff0000",
  "NOTE": "value with # hash",
  "EMPTY": null
}
GREETING="Hello, World"
MOTD="line one\nline two"
COLOR="#ff0000"
NOTE="value with # hash"
EMPTY=

Strings containing spaces, newlines, #, or quotes are automatically wrapped in double quotes and escaped so they survive a round-trip through dotenv. A null value becomes an empty assignment (KEY=).

Normalize keys to UPPER_SNAKE_CASE

{
  "databaseUrl": "postgres://localhost/mydb",
  "poolSize": 10,
  "enable-signup": true
}
DATABASE_URL=postgres://localhost/mydb
POOL_SIZE=10
ENABLE_SIGNUP=true

With the Normalize keys option on, camelCase and kebab-case keys are converted to the UPPER_SNAKE_CASE convention that environment variables use. With it off, the original keys are kept verbatim.

Nested object flattened to a JSON string

{
  "APP_NAME": "my-app",
  "FEATURES": { "signup": true, "beta": false },
  "REGIONS": ["us-east-1", "eu-west-1"]
}
APP_NAME=my-app
FEATURES="{\"signup\":true,\"beta\":false}"
REGIONS="[\"us-east-1\",\"eu-west-1\"]"

.env files are flat, so nested objects and arrays cannot be represented natively. The tool serializes each nested value to a compact JSON string and double-quotes it, and shows a warning listing which keys were flattened so the behavior is never silent.

How to Use

  1. 1

    Paste Your JSON Object

    Enter or paste a flat JSON object into the input field above. You can also click 'Load example' to try a config object, values that need quoting, or a nested object.

  2. 2

    See Live .env Output

    The .env file appears instantly in the output panel. Toggle 'Normalize keys' for UPPER_SNAKE_CASE names, or 'Add export prefix' if the file will be sourced in a shell.

  3. 3

    Copy or Download

    Click Copy to grab the .env to your clipboard, or Download to save it as a .env file — ready to drop into your project and load with dotenv.

Common JSON Pitfalls

Top-Level Array or Scalar

A .env file is a flat set of named variables, so the input must be a JSON object. A top-level array or a bare value like a string or number has no key names to map to variables, and the tool reports an error. Wrap your data in an object with descriptive keys first.

✗ Wrong
["a", "b", "c"]
✓ Correct
{"ITEMS": "a,b,c"}

Invalid JSON Syntax

The input must be valid JSON. Trailing commas, single quotes, and unquoted keys are common mistakes copied from JavaScript and cause a parse error with a line and column. Use double quotes for all keys and string values and remove any trailing commas.

✗ Wrong
{'PORT': 8080,}
✓ Correct
{"PORT": 8080}

Expecting Nested Structure in the .env

Nested objects and arrays cannot be represented natively in a flat .env file. The tool serializes them to JSON strings and warns you, but the value becomes a single opaque string. If you need the structure preserved, convert to YAML instead of .env.

✗ Wrong
{"DB": {"host": "localhost", "port": 5432}}
✓ Correct
{"DB_HOST": "localhost", "DB_PORT": 5432}

Keys That Are Not Valid Variable Names

Most shells and loaders only accept variable names matching [A-Za-z_][A-Za-z0-9_]* — a key that starts with a digit or contains spaces or dashes is invalid. With keys kept verbatim the tool warns you about such keys; Normalize keys fixes case and dashes but cannot rescue a name that starts with a digit, so rename those keys in your JSON.

✗ Wrong
{"2fa-enabled": true}
✓ Correct
{"TWO_FA_ENABLED": true}

Unquoted Strings That Need Quoting

If you hand-write the JSON, remember that a value with spaces or a # must still be a valid JSON string (in double quotes). The tool then re-quotes it for .env automatically. The mistake is forgetting the JSON quotes on the input side, which produces invalid JSON.

✗ Wrong
{"MSG": Hello World}
✓ Correct
{"MSG": "Hello World"}

Common Use Cases

Generate .env from a Config Export
Take a JSON configuration export from an API, a settings dashboard, or a secrets manager and turn it into a ready-to-use .env file for local development or a container.
Scaffold .env Templates
Build a JSON object describing the variables a new service needs, convert it to a .env, and commit a .env.example so teammates know exactly which keys to fill in.
Bridge JSON-Configured Tools to dotenv
Some tools emit configuration as JSON while your runtime expects a .env. Convert the JSON output into dotenv format so both halves of the pipeline agree on the same variables.
Produce Sourceable Shell env Files
Enable the export prefix to generate a file you can source directly in a shell or CI step, turning a JSON config blob into exported environment variables in one paste.
Round-Trip Configuration
Pair this with the .env to JSON Converter to edit configuration as structured JSON and write it back to .env — the round-trip-safe quoting guarantees values survive both directions.
Normalize Mixed-Case Keys
Convert a JSON object with camelCase or kebab-case keys into a .env with consistent UPPER_SNAKE_CASE variable names using the Normalize keys option, matching environment-variable conventions.

Technical Details

Object-Only Input with Typed Serialization
Input is parsed with the browser's native JSON.parse() and must be a top-level object; arrays and scalars are rejected with a clear error. Each top-level property is serialized by type: numbers and booleans are written bare, null becomes an empty value (KEY=), and strings are written directly unless they contain a space, newline, # or quote, in which case they are double-quoted and escaped for round-trip safety.
Nested Values and Key Normalization
Nested objects and arrays are serialized with a compact JSON.stringify, double-quoted and escaped, with a warning naming the flattened keys. The optional Normalize keys step converts keys to UPPER_SNAKE_CASE, resolving most invalid names; when keys are kept verbatim, any key that does not match [A-Za-z_][A-Za-z0-9_]* triggers an invalid-name warning. An optional export prefix can be added to every line.
Browser-Based — No Upload, No Server
All processing happens entirely in your browser's JavaScript engine; no JSON data is transmitted over the network at any point. The serializer is written in-house with no external dependencies, since the Node dotenv library is not browser-safe. Inputs larger than 200KB switch from live mode to manual mode (an explicit Convert click) to keep the browser responsive.

Best Practices

Keep Keys Verbatim Unless You Need env Conventions
Leave Normalize keys off when the consuming app already expects the exact key names in your JSON, so nothing is renamed unexpectedly. Turn it on only when you specifically want the UPPER_SNAKE_CASE convention environment variables conventionally use.
Flatten Nesting Intentionally, Not Accidentally
A nested value becomes an opaque JSON string in the .env, which most apps cannot parse back automatically. When you see the flattening warning, prefer reshaping the JSON into flat, prefixed keys (DB_HOST, DB_PORT) before converting, or choose a structured format like YAML instead.
Trust the Auto-Quoting for Round-Trips
Let the tool decide when to quote — it double-quotes and escapes only the values that need it. This keeps the .env readable while guaranteeing values with spaces, newlines or # survive a round trip back through the .env to JSON Converter unchanged.
Generate Secrets Only in a Browser-Only Tool
The JSON you convert here is effectively a set of credentials. Only generate a .env in a tool that runs entirely in the browser; verify zero network requests in DevTools. This converter qualifies, unlike server-side or API-backed generators.
Validate the JSON Input First
If the JSON is hand-written or assembled by a script, validate it with the JSON Formatter first to catch trailing commas or unquoted keys, so you get a clean .env instead of a confusing parse error.

Frequently Asked Questions

How do I convert JSON to a .env file online?
Paste a JSON object into the input field above. The tool generates a .env file instantly in your browser — no button click needed. Each top-level property becomes a KEY=VALUE line. You can optionally normalize keys to UPPER_SNAKE_CASE or add an export prefix from the Options panel, then click Copy to grab the result or Download to save it as a .env file. Everything runs locally, so your secrets never leave your device.
What kind of JSON does this accept?
The input must be a JSON object (a set of key/value pairs at the top level), because a .env file is fundamentally a flat list of variables. A top-level array or a bare scalar like a string or number cannot map to environment variables, so the tool reports an error asking for an object. Invalid JSON also produces an error with best-effort line and column numbers so you can locate the problem quickly.
How are strings, numbers, booleans and null written?
Numbers and booleans are written without quotes (PORT=8080, DEBUG=true). A null value becomes an empty assignment (KEY=), which dotenv loads as an empty string. Plain strings are written as-is, but a string containing spaces, a newline, a #, or a quote character is automatically wrapped in double quotes and escaped so it parses back correctly. This means the output round-trips cleanly through the dotenv parser and through our companion .env to JSON Converter.
What happens to nested objects and arrays?
.env files cannot represent nesting — every variable is a flat string. When a value is a nested object or array, the tool serializes it to a compact JSON string with JSON.stringify, wraps it in double quotes, and escapes it. A non-blocking warning lists exactly which keys were flattened this way, so you always know the structure was collapsed. If your data is deeply nested, a format like JSON to YAML preserves the hierarchy far better than .env can.
What does the Normalize keys option do?
By default the original JSON keys are kept exactly as written, so no data is lost — and in that mode any key that is not already a valid environment variable name (most shells and loaders only accept names matching [A-Za-z_][A-Za-z0-9_]*) is flagged with a warning so you can rename it. With Normalize keys enabled, keys are converted to UPPER_SNAKE_CASE — the conventional style for environment variables (databaseUrl becomes DATABASE_URL, enable-signup becomes ENABLE_SIGNUP) — which resolves most invalid names automatically.
Is my JSON data sent to a server?
No. All conversion happens entirely in your browser with JavaScript. The JSON you paste — which often holds API keys, database credentials and tokens you are about to write into a .env file — is never transmitted, never stored on any server, and never logged. You can confirm this by opening your browser's Network tab and watching that pasting triggers zero requests. That is what makes it safe to generate a real production .env, not just a sample.

Related Tools

View all tools →