typesafe-config

How does one specify multi-line strings in Typesafe Config?


I have the following configuration file that I want to use from Scala applying this library:

P11 {
    yes="0.0"
    no="1.0"
}

P12 {
    yes="0.01"
    no="0.99"
}

P13 {
id = "123 567 \
T 0: \
If (f 23 <= 0.0)"
}

This is how I do it:

import com.typesafe.config.ConfigFactory

val configFileName = "/usr/develop/tests/config.conf"
val parsedConfigMCF = ConfigFactory.parseFile(new File(configFileName))
val confMCF = ConfigFactory.load(parsedConfigMCF)

Then I get the error:

Expecting a value but got wrong token: 'newline' (backslash followed by 'newline', this is not a valid escape sequence

It looks like it does not like \ (backslash), but I need to put several lines for id in P13.


Solution

  • From official documentation of Typesafe Config:

    multi-line strings with triple quotes as in Python or Scala

    so:

    P13 {
      id = """123 567
    T 0:
    If (f 23 <= 0.0)"""
    }
    

    Careful with indentation on subseqent lines: any whitespace included at the beginning of the line will be included in the value.