Home → JSON to env Converter
Convert JSON configuration objects to .env environment variable format.
Convert JSON configuration objects to .env environment variable format. This tool runs entirely in your browser — no data is ever sent to a server. Free to use, no account required.
The .env format is the standard way to store environment-specific configuration variables outside of application code.
One variable per line in KEY=value format. No spaces around the equals sign. String values can optionally be quoted. Lines starting with # are comments. Variable names are conventionally uppercase with underscores.
Dotenv libraries (dotenv for Node.js, python-dotenv for Python) read .env files on application start and make each KEY available as an environment variable. This lets the same codebase run with different configuration in different environments.
JSON configuration objects from APIs or secrets managers can be directly converted to .env format for use in deployment pipelines.
Top-level string, number, and boolean keys become environment variable names (uppercased) and their values become the variable values. This is the most straightforward case and produces clean .env output.
Nested keys are flattened using double underscore (__) or single underscore separator. {"db": {"host": "localhost"}} becomes DB__HOST=localhost or DB_HOST=localhost depending on your preference.
Converting a JSON configuration object to .env format makes it easy to set up environment variables for Node.js, Docker, and CI/CD pipelines.
// JSON Input
{
"database_host": "localhost",
"database_port": 5432,
"database_name": "myapp",
"api_key": "sk-abc123",
"debug_mode": true,
"max_connections": 100
}
# .env Output
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=myapp
API_KEY=sk-abc123
DEBUG_MODE=true
MAX_CONNECTIONS=100
| Type | Rule | Example |
|---|---|---|
| Strings | No quotes needed for simple strings | API_KEY=myvalue |
| Strings with spaces | Wrap in double quotes | APP_NAME="My App" |
| Special characters | Quote and escape | DB_PASS="p@ss#w0rd!" |
| Comments | Lines starting with # | # This is a comment |
| Numbers | No quotes needed | PORT=3000 |
| Booleans | true or false (string) | DEBUG=true |
| Empty value | Leave value blank | OPTIONAL_VAR= |
# Node.js (dotenv)
npm install dotenv
// require("dotenv").config() at top of app
# Docker Compose
env_file:
- .env
# Python (python-dotenv)
pip install python-dotenv
from dotenv import load_dotenv; load_dotenv()
# GitHub Actions
env:
MY_VAR: ${{ secrets.MY_VAR }}
Converting JSON to .env format is a common task when moving configuration between secrets managers, CI/CD pipelines, and local development environments. Follow these steps to convert JSON to .env correctly every time.
database.host becomes DATABASE_HOST.. and - are not valid in environment variable names in most shells. Replace them with _.APP_NAME="My App".// Step 1: Original nested JSON (from AWS Parameter Store, config file, etc.)
{
"database": {
"host": "db.example.com",
"port": 5432,
"name": "production_db",
"password": "s3cur3p@ss!"
},
"app": {
"name": "My API Service",
"debug": false,
"allowed_origins": ["https://app.example.com", "https://admin.example.com"]
},
"stripe_secret_key": "sk_live_abc123"
}
// Step 2: Flatten nested keys with _ separator, uppercase all keys
// Step 3: Arrays → comma-separated strings; quote values with spaces/special chars
# .env output
DATABASE_HOST=db.example.com
DATABASE_PORT=5432
DATABASE_NAME=production_db
DATABASE_PASSWORD="s3cur3p@ss!"
APP_NAME="My API Service"
APP_DEBUG=false
APP_ALLOWED_ORIGINS="https://app.example.com,https://admin.example.com"
STRIPE_SECRET_KEY=sk_live_abc123
Both conversion directions are useful in different situations. JSON to .env is common when importing configuration from cloud services; .env to JSON is useful when you need to pass environment configuration to tools that expect a JSON input.
| Aspect | JSON to .env | .env to JSON |
|---|---|---|
| Common use case | Import from secrets manager, Vault, AWS SSM, or config API | Export env vars for Terraform, Docker Compose, or JSON-based config tools |
| Nesting support | Nested JSON is flattened to KEY_SUBKEY format | Flat env vars are converted to top-level JSON keys only |
| Array handling | Arrays stored as comma-separated strings | String values kept as strings; no automatic array reconstruction |
| Key casing | JSON keys uppercased → UPPER_SNAKE_CASE | Env var names kept as-is or converted to camelCase |
| Lossless round-trip | Not always — arrays and nested objects may lose structure | Possible for flat scalar values; nesting not reconstructed automatically |
| Best tool | This JSON to .env converter | dotenv-cli, env2json npm package, or a custom script |
Most .env files follow predictable naming conventions grouped by service or concern. Here are the most common patterns you will encounter in real projects:
# PostgreSQL / MySQL
DATABASE_URL=postgresql://user:pass@localhost:5432/mydb
DB_HOST=localhost
DB_PORT=5432
DB_NAME=myapp
DB_USER=appuser
DB_PASSWORD=secret
# Redis
REDIS_URL=redis://localhost:6379
REDIS_HOST=localhost
REDIS_PORT=6379
# Node.js / Express
NODE_ENV=production
PORT=3000
APP_SECRET=your-jwt-secret-here
CORS_ORIGIN=https://app.example.com
LOG_LEVEL=warn
# Next.js / React
NEXT_PUBLIC_API_URL=https://api.example.com
NEXT_PUBLIC_GA_ID=G-XXXXXXXXXX
# Payment
STRIPE_SECRET_KEY=sk_live_...
STRIPE_PUBLISHABLE_KEY=pk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...
# Email
SENDGRID_API_KEY=SG.xxxxx
SMTP_HOST=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER=apikey
SMTP_PASS=SG.xxxxx
# Storage
AWS_ACCESS_KEY_ID=AKIA...
AWS_SECRET_ACCESS_KEY=xxxxx
AWS_REGION=us-east-1
S3_BUCKET=my-app-uploads
# Feature toggles
FEATURE_NEW_DASHBOARD=true
FEATURE_BETA_API=false
MAINTENANCE_MODE=false
MAX_UPLOAD_SIZE_MB=50
Explore more tools: All JSON Tools | Validator | Pretty Print | JSON Diff