Return a static text with double quote json

1. Caddy version (caddy version):

v2.5.1

2. How I run Caddy:

a. System environment:

Ubuntu, right from the binary (./caddy)

b. Command:

./caddy run

d. My complete Caddyfile or JSON config:

handle_path /.well-known/matrix/client {
   respond "{"m.homeserver": {"base_url": "https://example.com"}}"
   header Access-Control-Allow-Origin "*"
}

3. The problem I’m having:

I need to return JSON with double quotes.

4. Error messages and/or full log output:

Error during parsing: Wrong argument count or unexpected line ending

5. What I already tried:

Using/adding backslahes

6. Links to relevant resources: Return a static text with double quote json

Hi :wave:

I posted a more elaborate response regarding static json responses in the context of matrix servers before, which I highly recommend to you here :innocent:


But just for the record, you could use both backslashes \ or backticks `:
The Caddyfile Concept docs (hotlink to “Tokens and quotes”) state:

Quotes can be escaped if you need to use quotes in quoted tokens, too:

directive "\"abc def\""

[…]

You can also use a backtick ` to quote tokens; these are convenient when tokens themselves contain double quotes, e.g. JSON text:

directive `{"foo": "bar"}`
3 Likes

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