How to convert a JSON JString value to an ordinary String in Lift?

Ivan picture Ivan · Oct 16, 2011 · Viewed 15.1k times · Source

Having a jString : JString value holding an "abc" string inside I get "JString(abc)" : String if I call jString.toString. How do I get "abc" : String instead?

Answer

Joni picture Joni · Oct 16, 2011

To extract a value from JValue you can use any method described here: What is the most straightforward way to parse JSON in Scala?

For instance:

json.extract[String]

You can use 'render' function to convert any JValue to printable format. Then either 'pretty' or 'compact' will convert that to a String.

compact(render(json))

or

pretty(render(json))