scalatypesafe

Typesafe config: get as map


googlesheets{
 dmkb_sheet = "1xEC8CPlKn654321wcoS_JB12345cPPiaA0M"
 other_sheet = "123isS0M30TH3R1D"
}

I would like to use something like myConfig.getAsMap("googlesheets") and get the two nested entries as a Map. No such method exists. So what is the easiest way to load the two nested entries as a Map?


Solution

  • For some definition of easy you could use something like this:

    val config = conf.atKey("googlesheets")
    config.root.keySet.asScala.map(key ⇒ key → config.getString(key)).toMap
    

    I would argue that it would be even easier to use a library for mapping configurations to case classes, like pureconfig