π Convert .env files to JSON format for easy import into AWS Secrets Manager and other secrets management services.
- π― Simple: Just run
env2jsonin any directory with a.envfile - π Clipboard: Automatically copies JSON to clipboard for easy pasting
- π Secure: Automatically masks sensitive values in preview output
- π Cross-platform: Works on macOS, Linux, and Windows WSL
- π Flexible: Specify custom input files with
--inputflag - πΎ Output options: Print to stdout (with clipboard) or save to file
- β‘ Fast: Single binary with no dependencies
# One-line install script (macOS/Linux) - configures PATH automatically
curl -sSL https://raw.githubusercontent.com/gbretas/env2json/main/install.sh | bash# After installation, you can use immediately:
env2json -helpDownload the appropriate binary for your platform from the releases page:
# macOS (Apple Silicon) - instala em ~/bin (padrΓ£o macOS)
curl -L -o env2json https://github.com/gbretas/env2json/releases/latest/download/env2json-darwin-arm64
chmod +x env2json && mkdir -p ~/bin && mv env2json ~/bin/
# macOS (Intel) - instala em ~/bin (padrΓ£o macOS)
curl -L -o env2json https://github.com/gbretas/env2json/releases/latest/download/env2json-darwin-amd64
chmod +x env2json && mkdir -p ~/bin && mv env2json ~/bin/
# Linux (x64) - instala em ~/.local/bin (padrΓ£o XDG)
curl -L -o env2json https://github.com/gbretas/env2json/releases/latest/download/env2json-linux-amd64
chmod +x env2json && mkdir -p ~/.local/bin && mv env2json ~/.local/bin/
# Linux (ARM64) - instala em ~/.local/bin (padrΓ£o XDG)
curl -L -o env2json https://github.com/gbretas/env2json/releases/latest/download/env2json-linux-arm64
chmod +x env2json && mkdir -p ~/.local/bin && mv env2json ~/.local/bin/
# Windows WSL
curl -L -o env2json.exe https://github.com/gbretas/env2json/releases/latest/download/env2json-windows-amd64.exegit clone https://github.com/gbretas/env2json.git
cd env2json
make build# Build and install (uses OS-specific standard directory)
make build && make install
# macOS: instala em ~/bin
# Linux: instala em ~/.local/bin
# Siga as instruΓ§Γ΅es para adicionar ao PATH se necessΓ‘rio# Convert .env in current directory (JSON to stdout + clipboard)
env2json
# Convert specific .env file
env2json -input .env.production
env2json -input /path/to/.env
# Save output to file (no clipboard)
env2json -output secrets.json
env2json -input .env.prod -output prod-secrets.json$ env2json
{
"API_KEY": "abc123def456",
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb",
"NODE_ENV": "development",
"PORT": "3000",
"DEBUG": "true"
}
# β JSON automatically copied to clipboard!$ env2json -input .env.production
{
"API_SECRET": "prod_secret_key",
"DATABASE_URL": "postgresql://prod-server:5432/app",
"ENVIRONMENT": "production"
}$ env2json -output secrets.json
Saved to secrets.json (5 variables)
$ cat secrets.json
{
"API_KEY": "abc123def456",
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb",
"NODE_ENV": "development",
"PORT": "3000",
"DEBUG": "true"
}$ env2json
No .env file found in current directory.
Use --input flag to specify a different .env file:
env2json --input /path/to/.env
env2json --input .env.production
$ env2json -input nonexistent.env
File not found: nonexistent.env# Generate secrets file
env2json -output secrets.json
# Import to AWS Secrets Manager
aws secretsmanager create-secret \
--name "my-app-secrets" \
--secret-string file://secrets.json# Convert .env and copy to clipboard
env2json
# Then paste directly in AWS Console Secrets Manager
# Or use AWS CLI with clipboard:
aws secretsmanager create-secret \
--name "my-app-secrets" \
--secret-string "$(pbpaste)" # macOS
# --secret-string "$(xclip -o)" # Linux# Convert and create k8s secret
env2json | kubectl create secret generic my-app-secrets --from-file=/dev/stdin
# Or save to file first
env2json -output secrets.json
kubectl create secret generic my-app-secrets --from-file=secrets.jsonenv2json -output secrets.json
az keyvault secret set --vault-name MyKeyVault --name app-secrets --file secrets.jsonIf env2json command is not found after installation:
# Check if binary exists
ls -la ~/.local/bin/env2json # Linux
ls -la ~/bin/env2json # macOS
# Add to PATH manually
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc # Linux
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc # macOS
# Reload shell
source ~/.bashrc # or ~/.zshrcIf clipboard doesn't work:
- macOS: Should work out of the box
- Linux: Install
xcliporxsel:sudo apt install xclip - Windows WSL: Install
clip(usually pre-installed)
# Empty .env file
$ env2json
The .env file is empty or contains no valid environment variables.
# Permission denied
$ env2json -input /etc/secrets.env
Error reading .env file: open /etc/secrets.env: permission denied# Build for current platform
make build
# Build for all platforms
make build-all
# Run tests
make test
# Install locally (OS-specific directory)
make install
# Clean build files
make clean
# Run locally
make run ARGS="-help"
make run ARGS="-input .env.test"env2json/
βββ main.go # Main CLI application
βββ main_test.go # Unit tests
βββ go.mod # Go module definition
βββ Makefile # Build automation
βββ install.sh # Installation script
βββ LICENSE # MIT license
βββ README.md # This file
βββ .github/workflows/ # GitHub Actions CI/CD
βββ build/ # Generated binaries
- Clean output: Only outputs JSON, no sensitive data leaked in logs
- No network calls: Purely local processing
- No data storage: Doesn't save or cache any environment data
- Clipboard only: Sensitive data only goes to clipboard (user controlled)
The tool supports standard .env file format with robust parsing:
# Comments are ignored
DATABASE_URL=postgresql://user:pass@localhost:5432/mydb
# Quoted values (quotes are automatically removed)
API_KEY="abc123def456"
JWT_SECRET='super-secret-key'
# Unquoted values
PORT=3000
DEBUG=true
# Empty lines are ignored
# Complex values
REDIS_URL=redis://username:password@redis-server:6379/0
ALLOWED_HOSTS=localhost,127.0.0.1,myapp.com- β
Comments: Lines starting with
#are ignored - β Empty lines: Automatically skipped
- β Quoted values: Single and double quotes removed
- β Complex values: URLs, comma-separated lists, etc.
- β Whitespace: Automatically trimmed
- β Invalid lines: Gracefully skipped
MIT License