Question

using net.liftweb.json what is the difference \ and \ operators when parsing json ?

import net.liftweb.json._
 val parsed = JsonParser.parse(jsonString)
 val name = parsed.\("firstName")
 val userId = parsed.\\("userId")
Was it helpful?

Solution

"\\" will extract the value even if it's present within nested json whereas "\" will extract the value only if present as a top-level attribute.

Consider this json

 val json = """{"nested1":{"nested2": {"myKey":"myValue"}}}"""
 val jsonMsg = parse(json)

In this case

 (jsonMsg \ "myKey").values

retruns None

where as

 (jsonMsg \\ "myKey").values

returns myValue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top