As an exercise and some in-house util i'm building, i'd like to convert a java properties file to json hierarchy
foo.bar=15
foo.lots.dir=/tmp/test
foo.baz.host=localhost
foo.baz.port=333
I've managed to converted to a scala map, here's the code:
import java.util._
import scala.io._
import scala.collection.JavaConverters._
import java.io._
val props : Properties = new Properties();
In a repl, you get
scala> props.asScala
res3: scala.collection.mutable.Map[String,String] = Map(foo.bar -> 15, foo.lots.dir -> /tmp/test, foo.baz.host -> localhost, foo.baz.port -> 333)
Question now becomes, how do I iterate this map and collapse the dot notation to a nested map:
Map(
foo -> Map(
bar -> 15,
baz -> Map(
port -> 333,
host -> localhost
)
)
)
perhaps using a scala recursion? ;-)
This will feed into a JSON builder and convert it to JSON format. (Which the code i'll post here as edit, once i figure out how to do the above nested map)