typesafetypesafe-configtypesafe-stack

How to parse typesafe config with objects


I have a config application.conf:

usersHasPermissions = [
  {"login": "admin", "perms": ["p1", "p2"]},
  {"login": "petooh", "perms": ["p2"]},
  {"login": "*", "perms": ["p3"]}
]

How I can parse it to Map[String,Set[String], where "login" - key, "perms" - set?

I can render it as json and parse. But I didn't want include json library in project. I think there is solution with ConfigObject etc.


Solution

  • Ok, it's simple:

    config.getObjectList("usersHasPermissions").asScala.map(o =>
          o.toConfig.getString("login") ->
            o.toConfig.getStringList("perms").asScala.toSet).toMap