JSON to Environment Variable Generator

Convert JSON configuration objects to environment variable format. Supports Docker .env, Kubernetes ConfigMap, and shell export formats.

What is JSON to Environment Variable Generator?

Environment variables are key-value pairs used by operating systems, containers, and application frameworks to configure behavior without hardcoding values into source code. This tool converts JSON configuration objects into environment variable formats by flattening nested structures into underscore-separated UPPER_SNAKE_CASE keys. It supports four output formats: .env files for Docker and Node.js (via dotenv), shell export statements for bash scripts and CI/CD pipelines, Docker Compose YAML with environment sections for container orchestration, and Kubernetes ConfigMap YAML for cluster configuration. Each format handles value quoting and escaping according to its specific syntax rules.

How to Use

  1. Paste your JSON configuration object into the input area — nested objects will be flattened automatically
  2. Select the desired output format using the format selector buttons (.env File, Shell Export, Docker Compose, or Kubernetes ConfigMap)
  3. Click "Convert" to generate the environment variable output in your chosen format
  4. Review the output for correctness — check that nested keys are properly flattened and special characters are quoted
  5. Copy the result and place it in your project: .env file at project root, docker-compose.yml, or k8s manifest

Why Use This Tool?

Generate .env files compatible with Docker Compose, Node.js dotenv, Python python-dotenv, and Ruby dotenv
Create Kubernetes ConfigMap YAML resources directly from JSON configuration for cluster deployment
Produce shell export statements for use in CI/CD scripts, Docker entrypoints, and bash provisioning
Automatic key flattening converts nested objects like {"database": {"host": "localhost"}} into DATABASE_HOST=localhost
Proper quoting for values containing spaces, equals signs, hash symbols, and other special characters
Docker Compose format generates a complete services section with environment variables ready to paste

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 since environment variables are always strings
  • Use the Kubernetes format for generating ConfigMap resources that can be applied directly with kubectl apply -f

Frequently Asked Questions

What is .env format and why is it used?

The .env format is a plain text file format that stores environment variables as KEY=VALUE pairs, one per line. It is widely adopted by Docker, Node.js (via the dotenv package), Python (python-dotenv), and many other frameworks. The primary benefit is keeping configuration separate from source code, which improves security by preventing sensitive values like API keys and database passwords from being committed to version control.

How are nested objects flattened into environment variable keys?

Nested objects are recursively flattened using underscore separators and converted to UPPER_SNAKE_CASE. For example, {"database": {"host": "localhost", "port": 5432}} becomes DATABASE_HOST=localhost and DATABASE_PORT=5432. This follows the standard convention for environment variable naming and ensures all values exist at a single level.

When should I NOT use environment variables for configuration?

Avoid environment variables for complex nested configuration, large data structures, or binary data. Environment variables are limited to string values and have platform-specific size limits. For configuration that requires deep nesting, typed values, or comments, consider using JSON, YAML, or TOML configuration files instead. Also, environment variables are not suitable for secret management at scale — use a dedicated secrets manager like HashiCorp Vault or AWS Secrets Manager.

How are arrays handled in the conversion?

Arrays are converted to comma-separated values. For example, {"ports": [80, 443]} becomes PORTS=80,443. If array elements are objects, they are serialized as JSON strings. For the Kubernetes ConfigMap format, arrays are rendered as multi-line YAML lists when appropriate.

Can I use this with Docker Compose?

Yes. The Docker .env format outputs standard KEY=VALUE pairs compatible with Docker Compose env_file directives and docker run --env-file. The Docker Compose format generates a complete docker-compose.yml services section with environment variables nested under the service, ready to merge into your existing compose file.

Is my configuration 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, database passwords, and private tokens.

Real-world Examples

Docker .env File for Microservice

Convert a nested JSON config to a .env file for a Docker Compose microservice stack.

Input
{"database": {"host": "db.internal", "port": 5432, "name": "myapp"}, "redis": {"url": "redis://cache:6379"}, "debug": true, "version": "2.1.0"}
Output
DATABASE_HOST=db.internal
DATABASE_PORT=5432
DATABASE_NAME=myapp
REDIS_URL=redis://cache:6379
DEBUG=true
VERSION=2.1.0

Kubernetes ConfigMap for Application Config

Generate a Kubernetes ConfigMap YAML from JSON configuration for deployment to a cluster.

Input
{"app": {"name": "web-api", "port": 8080, "log_level": "info"}}
Output
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  APP_NAME: web-api
  APP_PORT: 8080
  APP_LOG_LEVEL: info

Related Tools