Suppose I have an unknown bit of JSON, and I want to check if it has a form similar to this:
{
"foo": stuff
"bar": stuff
}
where stuff
is anything - integer, object, whatever. If I do something like this:
auto json = parseJSON("{}");
auto foo = json["foo"];
I will get a segfault. Is there any way to gracefully handle this (return null, throw exception, anything other than a segfault)?
Just use the D
in
operator, like with a D associative array:If you're using DMD 2.065 or older, you need to use
json.object
for thein
operator: