In your case, this does not work, because the contents of json["response"] not a dictionary, it is an array. SwiftyJSON cannot validate a valid dictionary key in an array.
It works with the dictionary, the condition is not met, as expected:
var json: JSON = ["response": ["key1":"value1", "key2":"value2"]] if json["response"]["someKey"].exists() { print("response someKey exists") }
The solution to your problem is to check if the content is really a dictionary before using .exists() :
if let _ = json["response"].dictionary { if json["response"]["someKey"].exists() { print("response someKey exists") } }
Moritz
source share