How to check if JSONValue of type object has a key?

Borislav Kosharov via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 6 13:28:46 PDT 2015


I'm using std.json for parsing json. I need to check if a 
specific string key is in JSONValue.object. The first thing I 
tried was:

JSONValue root = parseJSON(text);
if(root["key"].isNull == false) {
     //do stuff with root["key"]
}

But that code doesn't work, because calling root["key"] will 
throw an exception of key not fount if "key" isn't there.

I need some method `root.contains("key")` method to check if the 
object has a key.

Thanks in advance!



More information about the Digitalmars-d-learn mailing list