JSON
Generate JSON from .env files
JSON Command
The json command converts your environment variables into a JSON structure, which can be useful for front-end applications, documentation, or other systems that work better with JSON than .env files.
Usage
env-mage json [options]Options
| Option | Description | Default |
|---|---|---|
-e, --env <file> | Path to .env file | .env |
-o, --output <file> | Path to output JSON file | .env.json |
-v, --values | Include actual values instead of null placeholders | false |
Examples
Basic Usage
Convert .env to .env.json with placeholder values:
env-mage jsonThis will generate a JSON file where all values are replaced with null for security.
Include Actual Values
Generate a JSON with the actual environment variable values:
env-mage json --valuesCustom Input and Output
Specify custom input and output files:
env-mage json -e .env.development -o config.jsonOutput Format
By default, the JSON output will use null values to protect sensitive information:
{
"DATABASE_URL": null,
"API_KEY": null,
"DEBUG_MODE": null
}With the --values option, actual values are included:
{
"DATABASE_URL": "postgresql://user:password@localhost:5432/db",
"API_KEY": "sk_test_abcdef123456",
"DEBUG_MODE": "true"
}Use Cases
- Creating configuration templates for front-end applications
- Documenting available environment variables
- Converting environment configuration for systems that require JSON
- Preparing environment variable structures for documentation
Security Considerations
Use the --values flag with caution, as it will include the actual values from your .env file in the output JSON. This could expose sensitive information if the JSON file is committed to version control or shared inappropriately.