jsonscalaparsinglift

Convert JValue to String in Lift Scala


I have json string. I converted it to JValue using net.liftweb.JsonParser

val x : JValue =  parse(json)

Then i modified the value of a field called "name" using replace()

x.replace("name" :: Nil, JString("Tim"))

Question is how do i convert this JValue back to a json String


Solution

  • You can simply use this

    import net.liftweb.json._
    compact(render(x))
    

    Which will give you a json string version of the JValue object in this form

    String = {"name":"Tim"}