How to convert from caddyfile to json?

I am currently using caddyfile and it is working fine. However I have a need for layer4 which doesn’t support caddyfile.

How do I convert to using json? Right now its using the /etc/caddy/caddyfile?

Also is there an easy caddfyfile to json convertor so that I don’t have to write out what is working in caddyfile to json. I can just add the layer4 items items that I need. I found an online tool but looks like it hasn’t been updated in a while because it didn’t work.

caddy adapt --config /etc/caddy/Caddyfile --adapter caddyfile

I found this option but it compressed the text all together with the json formating.

Yep, use caddy adapt. You can use the --pretty flag to have it printed out nicely.

See the docs Command Line — Caddy Documentation or run caddy help adapt which shows the command’s documentation.

How do you switch from using caddyfile to json is my next question?

You haven’t filled out the help topic template, as per the forum rules.

So I can’t answer that without having more information about your setup, which OS you’re on, how you installed Caddy, etc.

I thought it was a basic enough question on how you would convert to using a json file instead of a Caddyfile.

If said above is not clear, let me help you to clarify the basic enough answer you are looking for

add --pretty to your option you found but compressed all together
and write your output into a file, say caddyfile.json to /var/www by using >>

Tada, your new basic enough answer:
caddy adapt --config /usr/local/www/Caddyfile --pretty >> /var/www/caddyfile.json

and if the space is too far apart in your json file , my method is open up the file in notepad , press Ctrl+H , replace ' ' ← (8 spaces) with ' ' <— (2 or more spaces)

Hopefully my answer is basic enough :blush:

That question is ambiguous though. There’s many different ways of running Caddy. You might run it as a systemd service, or in Docker, or manually via the command line, etc. Each of those have a different answer for how to make changes to how you run it.

Like I said, filling the help topic template is a rule here. If you don’t fill it out, it wastes both our time, because I don’t know the information I need to answer your questions accurately, so I have to repeat with additional questions, meaning we have more roundtrips.

1 Like
 volumes:
      - ./temp/caddy-config.json:/etc/caddy/caddy-config.json
      - ./certs/hx-dashboard.crt:/etc/caddy/hx-dashboard.crt
      - ./certs/hx-dashboard.key:/etc/caddy/hx-dashboard.key
      - hxd-dashboard-proxy:/data
    command: ["caddy", "run", "--config", "/etc/caddy/caddy-config.json"]

https://caddy.community/t/cant-connect-to-database-behind-layer4-server/16168
I ended up using the clip found here to determine how to switch from using caddyfile in docker to json.

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