Extract Options from potentially null JSON values using for expression

后端 未结 4 1759
日久生厌
日久生厌 2021-01-19 02:09

I have a JSON document where some values can be null. Using for expressions in json4s, how I can yield None, instead of nothing?

The following will fail to yield whe

4条回答
  •  花落未央
    2021-01-19 02:57

    What about this

     for {
          JObject(thing) <- res1      
          x = thing.find(_._1 == "PlanEstimate").flatMap(_._2.toOption.map(_.values))
         } yield x
    

提交回复
热议问题