jsonscalacollectionsplayframeworkscala-collections

Check if a key exists in play.api.libs.json.Json


contains like functionality for play.api.libs.json.Json

val data=Map("id" -> "240190", "password" -> "password","email" -> "email@domain.com")

data.contains("email")//true


val info=Json.obj("id" -> "240190", "password" -> "password","email" -> "email@domain.com")

now how to check info contains email or not?


Solution

  • 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.