lift what is the difference \ and \\ operators when parsing json

59 views Asked by At

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")
1

There are 1 answers

0
Vishal John On BEST ANSWER

"\\" 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