json4s - Generating json in this format using Scala -
i have string :
"[[{\"cfunction\":\"sum\"},{\"cfunction\":\"groupby\"}],[{\"cfunction\":\"add here\"}]]"; which generated :
val json2 = list(list(("cfunction" -> "sum"), ("cfunction" -> "groupby")), list(("cfunction" -> "add here"))) println(compact(render(json2))) how generate : "[[{\"cfunction\":\"sum\" , \"1\":\"1\"},{\"cfunction\":\"groupby\" , \"2\":\"2\"}],[{\"cfunction\":\"add here\"}]]"; ?
i've tried :
val json2 = list(list(("cfunction" -> "sum" , "1" -> "1"), ("cfunction" -> "groupby", "2" -> "2")), list(("cfunction" -> "add here"))) but causes compiler error :
type mismatch; found : list[list[(java.io.serializable, java.io.serializable)]] required: org.json4s.jvalue (which expands to) org.json4s.jsonast.jvalue
use map?
scala> import org.json4s._ import org.json4s._ scala> import org.json4s.native.jsonmethods._ import org.json4s.native.jsonmethods._ scala> import org.json4s.jsondsl._ import org.json4s.jsondsl._ scala> val json2 = list(list(map("cfunction" -> "sum" , "1" -> "1"), map("cfunction" -> "groupby", "2" -> "2")), list(map("cfunction" -> "add here"))) json2: list[list[scala.collection.immutable.map[string,string]]] = list(list(map(cfunction -> sum, 1 -> 1), map(cfunction -> groupby, 2 -> 2)), list(map(cfunction -> add here))) scala> println(compact(render(json2))) [[{"cfunction":"sum","1":"1"},{"cfunction":"groupby","2":"2"}],[{"cfunction":"add here"}]]
Comments
Post a Comment