What is JSON to Environment Variable Generator?
This tool converts JSON configuration objects into environment variable formats. Nested objects are flattened using underscore-separated keys converted to UPPER_SNAKE_CASE. It supports four output formats: .env files for Docker and Node.js, shell export statements for bash scripts, Docker Compose YAML with environment sections, and Kubernetes ConfigMap YAML for cluster configuration.
How to Use
- Paste your JSON configuration object into the input area.
- Select the desired output format (.env, Shell, Docker Compose, or Kubernetes).
- Click 'Convert' to generate the environment variable output.
- Copy the result and use it in your project configuration.
Why Use This Tool?
Tips & Best Practices
- Nested keys are joined with underscores: {"database": {"host": "localhost"}} becomes DATABASE_HOST=localhost
- Arrays become comma-separated values: {"ports": [80, 443]} becomes PORTS=80,443
- Null values become empty strings: {"timeout": null} becomes TIMEOUT=
- Boolean and number values are preserved as strings in .env format
- Use the Kubernetes format for generating ConfigMap resources directly
Frequently Asked Questions
What is .env format?
The .env format is a plain text file format used to store environment variables as KEY=VALUE pairs, one per line. It is widely used by Docker, Node.js (via dotenv), Python, and many other frameworks to manage configuration outside of source code.
How are nested objects handled?
Nested objects are flattened using underscore separators and converted to UPPER_SNAKE_CASE. For example, {"database": {"host": "localhost"}} becomes DATABASE_HOST=localhost. This follows the standard convention for environment variable naming.
What about arrays?
Arrays are converted to comma-separated values. For example, {"ports": [80, 443]} becomes PORTS=80,443. For Kubernetes ConfigMap format, arrays are rendered as multi-line YAML lists.
Can I use this with Docker?
Yes. The Docker .env format outputs standard KEY=VALUE pairs compatible with Docker Compose and Docker run --env-file. The Docker Compose format generates a complete docker-compose.yml services section with environment variables.
Is my data sent to a server?
No, all conversion happens entirely in your browser. Your JSON configuration data 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 .env File
Convert a JSON config to a .env file for Docker Compose.
{"database": {"host": "localhost", "port": 5432}, "debug": true}DATABASE_HOST=localhost DATABASE_PORT=5432 DEBUG=true
Kubernetes ConfigMap
Generate a Kubernetes ConfigMap YAML from JSON configuration.
{"app": {"name": "myapp", "port": 8080}}apiVersion: v1 kind: ConfigMap metadata: name: app-config data: APP_NAME: myapp APP_PORT: 8080