I)You can use Try
val cols = Try {(json \ "responseBody" \ "columns")}
you can match it:
cols match {
case Success(value) => ???
case Failure(exception) =>
println(exception.getMessage)
}
II)You can convert it to Option to avoid exception
val cols = Try {(json \ "responseBody" \ "columns")}.toOption
It gives None or Some(value).
cols match {
case Some(value) => ???
case None => ??
}
II) You can use asOpt
val cols = (json \ "responseBody" \ "columns").asOpt[String].getOrElse("")
OR
val cols = (json \ "responseBody" \ "columns").asOpt[String].orNull
You can use
Try:val cols = Try {(json \ "responseBody" \ "columns")}you can match it:
cols match { case Success(value) => ??? case Failure(exception) => println(exception.getMessage) }You can convert it to Option to avoid exception
val cols = Try {(json \ "responseBody" \ "columns")}.toOptionIt gives
NoneorSome(value).cols match { case Some(value) => ??? case None => ?? }You can use
asOptval cols = (json \ "responseBody" \ "columns").asOpt[String].getOrElse("")OR
val cols = (json \ "responseBody" \ "columns").asOpt[String].orNull