Skip to main content
remove indentation on helper text so it doesn't look like a code dump
Source Link
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
  1. 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)
    }
    
  2. 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 => ??
    }
    
  3. You can use asOpt

    val cols = (json \ "responseBody" \ "columns").asOpt[String].getOrElse("")  
    

    OR

    val cols = (json \ "responseBody" \ "columns").asOpt[String].orNull
    
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
  1. 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)
    }
    
  2. 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 => ??
    }
    
  3. You can use asOpt

    val cols = (json \ "responseBody" \ "columns").asOpt[String].getOrElse("")  
    

    OR

    val cols = (json \ "responseBody" \ "columns").asOpt[String].orNull
    
Source Link

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