How to convert JValue to JObject

2,155 views
Skip to first unread message

antoine no

unread,
Feb 9, 2012, 4:28:47 AM2/9/12
to Lift
Hello,

I would like to know how to convert a JValue to a JObject from json.JsonAST ?
val r: JObject = ("key" -> JString("value")).replace(List("key"), JString("another value") //fails

thanks you.

Joni Freeman

unread,
Feb 10, 2012, 1:41:46 AM2/10/12
to lif...@googlegroups.com
Hi,

Here it is no longer statically known that the JSON represents an object since 'replace' returns
JValue. Thus you need a runtime cast. Is it possible to modify your code so that you operate with
JValues instead of JObjects? Then no cast is needed.

Cheers Joni

Maciej Bąk

unread,
Jul 7, 2015, 9:38:42 AM7/7/15
to lif...@googlegroups.com, antoi...@gmail.com

You can do this way:

jval match {
  case j @ JObject(jobj) => // do smth
  case _ => // err
}

this works fine.
Reply all
Reply to author
Forward
0 new messages