contains
like functionality for play.api.libs.json.Json
val data=Map("id" -> "240190", "password" -> "password","email" -> "[email protected]")
data.contains("email")//true
val info=Json.obj("id" -> "240190", "password" -> "password","email" -> "[email protected]")
now how to check info
contains email
or not?
Return valueJsonObject::containsKey() returns a bool that tells whether the key was found or not: true if the key is present in the object. false if the key is absent of the object.
You use the JSValue class to convert basic values, such as numbers and strings, between JavaScript and Objective-C or Swift representations to pass data between native code and JavaScript code.
The Play JSON API provides implicit Writes for most basic types, such as Int , Double , String , and Boolean . It also supports Writes for collections of any type T that a Writes[T] exists. import play. json.
info.keys.contains("email")
The .keys
gives you back a Set
with the key values and then you can call the contains
method, I'm not sure there's a more direct way to do it.
(info \ "email").asOpt[String].isEmpty
as asOpt would return Optional, we can have isEmpty simple check, this would do what we want.
(info \ "email").asOpt[String] match {
case Some(data) => println("here is the value for the key email represented by variable data" + data)
case None => println("email key is not found")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With