Splitting up a line in a HOCON file

1.7k views Asked by At

I have file in HOCON format where a very long string is assigned to a key. The string contains single quotes (and other "illegal" characters), and hence I need to enclose the value in double quotes. Something like this:

key="extremely long string with 'illegal' characters :;/. bla bla ..."

For readability, I would like to split this up into multiple lines. I simple have not found a way to do this. If the string weren't enclosed by double quotes, I could use \ to split lines. And if I didn't care about adding newlines, I could use """. But I do care about these things.

I have studied the informal HOCON specs but have still not found a solution.

(Since HOCON resembles JSON (which I don't know anything about), I have tagged this question with "JSON" as well.)

2

There are 2 answers

0
Andrei Pozolotin On BEST ANSWER

you could use hocon self-refs - for example, hocon section:

simple.database {

host = "db-server"
port = "5432"
name = "postgres"
user = "postgres"
pass = "postgres"

connection {
    driver = "org.postgresql.Driver"
    url = "jdbc:postgresql://"${simple.database.host}":"${simple.database.port}
    url = ${simple.database.connection.url}"/"${simple.database.name}
    url = ${simple.database.connection.url}"?ssl="true
    url = ${simple.database.connection.url}"&user="${simple.database.user}
    url = ${simple.database.connection.url}"&password="${simple.database.pass}
}

}

produces after resolution:

url = "jdbc:postgresql://db-server:5432/postgres?ssl=true&user=postgres&password=postgres"
1
Adam Lane On

I wanted to split up a very long content security policy but """ added newlines to the header causing issues. Just breaking up each section worked out for me. Thanks to Andrei's solution above for helping me think out of the box to combine different lines into one.

default-src = "default-src 'self';"
connect-src = "connect-src 'self';"
img-src = "img-src 'self';"
style-src = "style-src 'self';"

play.filters.headers.contentSecurityPolicy = ${default-src} ${connect-src} ${img-src} ${style-src}