Adapter Json to Caddyfile

I know we can go from a caddyfile → json using the native adapter. But what about json → caddyfile. Is there a plugin/adapter for this?
Use case: I’m writing something to dynamically create a caddy config using json (because json is more suitable for this purpose). But would still like to show the user the easier to read caddyfile.

There’s nothing for this, because it’s not a 1:1 mapping. Trying to convert from JSON back to Caddyfile would be lossy.

The Caddyfile implements a bunch of shortcuts to avoid duplication. To try to go in reverse, and preserve the same behaviour, would be very difficult to implement (lots of reverse engineering of each UnmarshalCaddyfile function) or in some cases impossible (e.g. you wouldn’t be able to regain import statements or snippets), and brittle (because it wouldn’t be maintained in core, any changes made in Caddy itself, or even any plugin, may break it).

1 Like

That makes sense. Even if import/snippets weren’t supported it would be too complicated since there isn’t a native way to do it.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.