0

I have this String :

"[[{\"cfunction\":\"sum\"},{\"cfunction\":\"groupBy\"}],[{\"cfunction\":\"Add Here\"}]]";

Which is generated by :

val json2 = List(List(("cfunction" -> "sum"), ("cfunction" -> "groupBy")), List(("cfunction" -> "Add Here")))
println(compact(render(json2)))

How to 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 this 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

1 Answer 1

1

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"}]]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.