caddy adapt command adapts a configuration to Caddy’s native JSON format and outputs the result.
Usage
Description
Adapts a configuration to Caddy’s native JSON format and writes the output to stdout, along with any warnings to stderr. This is useful for:- Previewing how your Caddyfile will be converted to JSON
- Debugging config adapter behavior
- Validating your config syntax
- Learning Caddy’s JSON structure
- Generating JSON configs from other formats
Flags
Configuration file to adapt (required).Use
- to read from stdin instead of a file.Name of config adapter to use.Default:
caddyfileAvailable adapters depend on what’s compiled in. Common ones:caddyfile- Caddyfile formatyaml- YAML format (if installed)
Format the output with indentation for human readability.Without this flag, output is compact JSON on a single line.
Validate the adapted config.If the config is invalid, an error will be printed to stderr and a non-zero exit status will be returned.
Environment file(s) to load in KEY=VALUE format.Useful if your config references environment variables.
Examples
Basic adaptation
Pretty-printed output
Adapt and validate
Adapt from stdin
Save to file
Adapt with environment variables
{env.VARIABLE}, the environment file will be loaded.
Adapt YAML config
Output
The adapted JSON is written to stdout, and any warnings are written to stderr.Exit Codes
0- Success1- Failed (adaptation error or validation error)
Warnings
Warnings are printed to stderr with file location:Validation
With the--validate flag, the adapted config is:
- Unmarshaled into Go structs
- Validated by calling
Validate()on all modules - Checked for errors
Validation catches many errors but not all. Some errors only appear at runtime when the config is actually loaded.
Use Cases
1. Preview before applying
2. Generate production JSON
3. Debug config issues
4. Learn JSON structure
Write a simple Caddyfile feature, then adapt it to see the JSON equivalent:5. CI/CD validation
Related Commands
caddy validate- Validate without adapting (if already JSON)caddy reload- Apply a config to running Caddycaddy run- Start Caddy with a config