.env · transform🔒 100% client-side — never leaves your browser

JSON to ENV Converter

Convert JSON to .env in one paste: this JSON to ENV converter flattens nested objects into UPPER_SNAKE_CASE keys, quotes values that would break a dotenv parser, and runs entirely in your browser.

By Aliniyaz Mamat · last reviewed

Be the first to rate
DATABASE_URL=postgres://user:pass@localhost:5432/db
PORT=3000
DEBUG=true
STRIPE_SECRET_KEY=sk_test_xxx
STRIPE_WEBHOOK=whsec_xxx

Key takeaways

  • ✓Nested keys are joined with _ and uppercased: database.url becomes DATABASE_URL.
  • ✓Values containing spaces, #, quotes, $ or line breaks are wrapped in double quotes, so abc#123 is not cut off at the #.
  • ✓Arrays are kept as a JSON string (["a","b"]) because a .env value is always a single string.
  • ✓Types are lost: 3000 and true become strings, so your app has to parse them again.
  • ✓Nothing is uploaded. The conversion is plain JavaScript in this tab, which matters when the JSON holds secrets.

What it does

  • ▸Converts any JSON object into a valid .env file
  • ▸Flattens nested objects into UPPER_SNAKE_CASE keys joined with _
  • ▸Replaces characters that are invalid in env names (dots, dashes, spaces) with _
  • ▸Quotes values with spaces, #, quotes, $ or newlines
  • ▸Copy or download the result as .env, 100% client-side

Privacy

Runs 100% in your browser. Your .env never touches our servers.

client-side only

Usage examples

Case 1 · Nested config → flat keys
{
  "database": { "url": "postgres://app@localhost:5432/app" },
  "auth": { "jwt_secret": "s3cr3t" },
  "port": 3000
}
DATABASE_URL=postgres://app@localhost:5432/app
AUTH_JWT_SECRET=s3cr3t
PORT=3000
Case 2 · Unsafe characters get quoted
{
  "smtp": { "password": "abc#123" },
  "app_name": "My App"
}
SMTP_PASSWORD="abc#123"
APP_NAME="My App"
Case 3 · Arrays and null
{
  "allowed-origins": ["https://a.com", "https://b.com"],
  "sentry_dsn": null
}
ALLOWED_ORIGINS="[\"https://a.com\",\"https://b.com\"]"
SENTRY_DSN=

When to use this tool

  • →Moving from a config.json or appsettings-style file to environment variables
  • →Turning firebase functions:config:get output into a .env for the v2 functions
  • →Creating a local .env from a JSON export of a secrets manager (AWS Secrets Manager, Doppler, 1Password CLI)
  • →Feeding JSON settings into docker run --env-file or a Kubernetes Secret

Common mistakes

  • ⚠Expecting arrays to come back as arrays. A .env value is a string; parse it with JSON.parse in your app
  • ⚠Forgetting that numbers and booleans become strings: process.env.PORT is "3000", not 3000
  • ⚠Key collisions: {"a_b": 1, "a": {"b": 2}} both flatten to A_B, and the last one wins
  • ⚠Committing the generated .env. Add it to .gitignore before you save it in the project

How the JSON to .env conversion works

A .env file is a flat list of KEY=value lines, while JSON can nest objects to any depth. The converter walks the object and builds one variable per leaf value. Each step down into an object adds the key and an underscore to the name.

  1. Flatten: {"stripe": {"webhook": {"secret": "whsec_…"}}} becomes the path stripe_webhook_secret.
  2. Normalize the name: the path is uppercased and every character outside A-Z, 0-9 and _ turns into _, so allowed-origins becomes ALLOWED_ORIGINS.
  3. Serialize the value: strings and numbers are written as they are, null becomes an empty value, arrays become a JSON string.
  4. Quote when needed: a value with whitespace, #, a quote, $, a backslash or a line break is wrapped in double quotes, and inner double quotes are escaped.

Want the opposite direction? The ENV to JSON converter parses a .env back into an object and can turn "true" and "3000" back into real booleans and numbers.

What changes when JSON becomes a .env file

JSON input.env outputWhat your app receives
"port": 3000PORT=3000the string "3000"
"debug": trueDEBUG=truethe string "true" (truthy even when it says "false")
"tags": ["a","b"]TAGS="[\"a\",\"b\"]"a JSON string, parse with JSON.parse
"dsn": nullDSN=an empty string, or undefined with some loaders
"db": {"url": "…"}DB_URL=…one flat variable per leaf

The safest pattern is to validate and cast once at startup, for example with zod in Node.js or pydantic-settings in Python, instead of calling Number() all over the codebase. The .env validator catches malformed lines before your app does.

Converting JSON to .env on the command line

For a flat JSON object without nesting, jq does the job in CI pipelines:

# flat object only: {"PORT": 3000, "NODE_ENV": "production"}
jq -r 'to_entries[] | "\(.key)=\(.value)"' config.json > .env

# AWS Secrets Manager (SecretString is a JSON object)
aws secretsmanager get-secret-value --secret-id prod/app \
  --query SecretString --output text \
  | jq -r 'to_entries[] | "\(.key)=\(.value)"' > .env

These one-liners do not flatten nested objects and do not quote values containing # or spaces. For anything nested or containing passwords, paste it into the converter above, then run the result through the .env formatter if you want aligned, sorted output.

Frequently asked questions

How are nested JSON objects converted to .env keys?

Each level is joined with an underscore and the result is uppercased, so {"database": {"url": "…"}} becomes DATABASE_URL=…. The separator is always _, which is the convention most config libraries expect.

Are JSON arrays supported?

Yes, but they stay a string. ["a","b"] is written as a quoted JSON string, because dotenv has no array type. Parse it with JSON.parse(process.env.TAGS) or split a comma-separated value instead.

Why are some values wrapped in quotes?

Unquoted, dotenv treats # as the start of a comment and drops it and everything after it, and line breaks end the value. The converter quotes those values so they survive parsing unchanged.

Can I convert the .env back to JSON?

Yes, with the ENV to JSON converter. Nesting does not come back automatically: DATABASE_URL stays a top-level key, because the underscore could also be part of the original name.

Is it safe to paste secrets into this converter?

The page converts in your browser and sends nothing to a server. You can check it in the DevTools Network tab while you paste. Still, treat the result like any secret: don't paste it into chats or commit it.

Related tools

Learn more

Compare

coming soon

Get notified when env syncing launches

We're building a tiny tool to keep .env files in sync across teammates and environments. Leave your email — no spam, just a single launch ping.

We use your address only for this launch email. You can ask us to delete it at any time. Privacy policy