Something like this should accomplish what you are looking to do. It will generate your test Map
and then serialize that to a JSON
String and write it out to a file. The next step will read it back in and extract it to a Map which you can read from - as in your above example.
import net.liftweb.json._
import java.io._
implicit val formats = net.liftweb.json.DefaultFormats
val map = {
val mb = new scala.collection.mutable.HashMap[String, Any]()
(1 to 10000).foreach { i =>
val in_list = "dummy" :: "dummy" :: "dummy" :: Nil
val in_map = Map("dummy%s".format(i) -> in_list)
mb += "dummy%s".format(i) -> List("cat1", "hash1", 100, (System.currentTimeMillis()/1000).toInt, in_map)
}
mb.toMap
}
val json = Extraction.decompose(map)
val jsonStrOut = Printer.pretty(JsonAST.render(json))
val fileName = "foo.txt"
val fw = new FileWriter(fileName)
fw.write(jsonStrOut)
fw.close()
val jsonStrIn = scala.io.Source.fromFile(fileName).mkString
val obj = parse(jsonStrIn).asInstanceOf[JObject].values
println(obj("dummy3"))
While this is doable, I would highly recommend taking advantage of case classes
and other Scala constructs to help with the serialization and de-serialization. Lift is really good at working with those object. Unless there is a reason for having everything untyped in a big Map, I think you'll save yourself a lot of headaches in the long run.