What is JSON to Dotenv Converter?
JSON and .env (dotenv) files serve different purposes in application configuration: JSON excels at representing nested, hierarchical data structures, while .env files store flat environment variables in `KEY=VALUE` format that Docker, Node.js, Python, and most deployment platforms consume natively. This bidirectional converter handles both directions — flattening nested JSON objects into .env files with `UPPER_SNAKE_CASE` keys joined by underscores (e.g. `{"database": {"host": "localhost"}}` becomes `DATABASE_HOST=localhost`), and reconstructing nested JSON from .env files by parsing underscore-separated keys back into object hierarchies. Arrays use index notation (`PORTS_0=80`, `PORTS_1=443`), and values containing spaces or special characters are automatically quoted in the .env output. The reverse conversion auto-detects booleans, numbers, and null values from .env strings.
How to Use
- Choose the conversion direction using the toggle button — JSON to .env for deployment configs, or .env to JSON for programmatic access
- Paste your JSON config or .env file content into the input area
- Click 'Convert' to produce the output in the target format
- Copy the result and save it as .env in your project root (for Docker Compose, Node.js, etc.) or use it in your application code
- For Docker Compose, paste the .env output into a .env file next to your docker-compose.yml — Compose automatically reads it
Why Use This Tool?
Tips & Best Practices
- Nested JSON keys are joined with underscores — {"database": {"host": "localhost"}} becomes DATABASE_HOST=localhost. All keys are converted to UPPER_SNAKE_CASE
- Arrays use index notation — {"ports": [80, 443]} becomes PORTS_0=80 and PORTS_1=443. Array items that are objects are further flattened with the index as prefix
- Values containing spaces, equals signs, hash characters, or quotes are automatically wrapped in double quotes in the .env output to prevent shell parsing errors
- When converting .env back to JSON, the tool reconstructs nested objects from underscore-separated keys by splitting on underscores and building the hierarchy — DATABASE_HOST=localhost becomes {"database": {"host": "localhost"}}
- Never commit .env files to version control — add .env to your .gitignore. Use .env.example with dummy values for documentation instead
Frequently Asked Questions
How are nested JSON objects flattened?
Nested objects are flattened using underscore-separated keys with UPPER_SNAKE_CASE conversion. For example, {"database": {"host": "localhost"}} becomes DATABASE_HOST=localhost. The nesting depth is unlimited — deeply nested objects produce longer key names but are always flattened to a single level.
When should I avoid using this converter?
Skip this tool if your JSON config has deeply nested structures (3+ levels) — the resulting .env key names become very long and hard to read. Also avoid it if you need to preserve type information in the .env output, since all values become strings. For complex configs, consider YAML or TOML instead.
How are arrays converted?
Arrays use index notation. For example, {"ports": [80, 443]} becomes PORTS_0=80 and PORTS_1=443. If array items are objects, they are further flattened with the index as part of the key prefix. The reverse conversion does not reconstruct arrays from indexed keys.
Can I convert .env back to JSON?
Yes. Use the direction toggle to switch to '.env to JSON' mode. The tool parses KEY=VALUE pairs and attempts to reconstruct nested objects from underscore-separated keys. Boolean, number, and null values are automatically detected — true becomes a boolean, 5432 becomes a number, and null becomes null.
What value types are supported?
The tool handles strings, numbers, booleans, and null values. In JSON to .env mode, all values are converted to their string representation. In .env to JSON mode, the tool auto-detects booleans (true/false), numbers, and null values and converts them to their proper JSON types.
Is my data secure?
Yes. All processing happens entirely in your browser. Your JSON and .env content is never sent to any server. No data is collected, stored, or transmitted. You can safely convert configs containing sensitive values like API keys and database passwords.
Real-world Examples
Docker Compose environment config
Convert a JSON configuration file into a .env file for use with Docker Compose, which automatically reads .env files for variable substitution.
{
"database": {
"host": "localhost",
"port": 5432,
"name": "myapp_production"
},
"server": {
"host": "0.0.0.0",
"port": 3000,
"debug": false
},
"api_key": "sk-abc123def456"
}DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_NAME=myapp_production SERVER_HOST=0.0.0.0 SERVER_PORT=3000 SERVER_DEBUG=false API_KEY=sk-abc123def456
Vercel environment variables from JSON
Flatten a Next.js configuration JSON into environment variables for Vercel deployment, where each variable is set individually in the dashboard.
{
"nextauth": {
"url": "https://myapp.vercel.app",
"secret": "my-secret-key"
},
"database": {
"url": "postgresql://user:pass@host:5432/db"
},
"enable_analytics": true
}NEXTAUTH_URL=https://myapp.vercel.app NEXTAUTH_SECRET=my-secret-key DATABASE_URL=postgresql://user:pass@host:5432/db ENABLE_ANALYTICS=true