score:29

Accepted answer

You can "decompose" a case class into JSON and then render it. Example:

scala> import net.liftweb.json.JsonAST._
scala> import net.liftweb.json.Extraction._
scala> import net.liftweb.json.Printer._    
scala> implicit val formats = net.liftweb.json.DefaultFormats

scala> case class MyBean(name: String, age: Int)
scala> pretty(render(decompose(MyBean("joe", 35))))
res0: String = 
{
  "name":"joe",
  "age":35
}

But sometimes it is easier to use DSL syntax:

scala> import net.liftweb.json.JsonDSL._
scala> val json = ("name" -> "joe") ~ ("age" -> 35)
scala> pretty(render(json))
res1: String = 
{
  "name":"joe",
  "age":35
}

Related Query

More Query from same tag