Skip to main content
The 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

string
required
Configuration file to adapt (required).Use - to read from stdin instead of a file.
string
default:"caddyfile"
Name of config adapter to use.Default: caddyfileAvailable adapters depend on what’s compiled in. Common ones:
  • caddyfile - Caddyfile format
  • yaml - YAML format (if installed)
boolean
default:"false"
Format the output with indentation for human readability.Without this flag, output is compact JSON on a single line.
boolean
default:"false"
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.
string[]
default:"[]"
Environment file(s) to load in KEY=VALUE format.Useful if your config references environment variables.

Examples

Basic adaptation

Outputs compact JSON to stdout.

Pretty-printed output

Outputs formatted JSON:

Adapt and validate

This ensures the adapted JSON config is valid before using it.

Adapt from stdin

Save to file

Adapt with environment variables

If your Caddyfile uses {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 - Success
  • 1 - Failed (adaptation error or validation error)

Warnings

Warnings are printed to stderr with file location:
Warnings don’t cause the command to fail, but you should review them.

Validation

With the --validate flag, the adapted config is:
  1. Unmarshaled into Go structs
  2. Validated by calling Validate() on all modules
  3. Checked for errors
If validation fails:
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