7

The documentation for lift-json suggests that I should be able to call 'values' to get my current JObject structure as a vanilla Scala Map. This approach is not working for me, as the return type of 'values' is json.Values rather than a Map as the examples show. What am I doing wrong? Is there an implicit import necessary to accomplish this conversion?

scala> val json = parse("""{"k1":"v1","k2":"v2"}""")         
json: net.liftweb.json.package.JValue = JObject(List(JField(k1,JString(v1)), JField(k2,JString(v2))))

scala> json.values                                  
res4: json.Values = Map((k1,v1), (k2,v2))

scala> res4.get("k1")                                        
<console>:18: error: value get is not a member of json.Values
   res4.get("k1")
Janx
  • 3,285
  • 3
  • 19
  • 24
  • 1
    possible duplicate of [Can I use the Scala lift-json library to parse a JSON into a Map?](http://stackoverflow.com/questions/3843000/can-i-use-the-scala-lift-json-library-to-parse-a-json-into-a-map) – Janx Apr 06 '11 at 21:39

1 Answers1

9

Somehow I missed the duplicate of this in my search: Can I use the Scala lift-json library to parse a JSON into a Map?

Answer is to cast explicitly:

json.asInstanceOf[JObject].values
Community
  • 1
  • 1
Janx
  • 3,285
  • 3
  • 19
  • 24