On 14.11.2015 07:30, MesmerizedInTheMorning wrote:
https://issues.dlang.org/show_bug.cgi?id=15331

but it's true !

There's **nothing** to check the availability of a Key. At least I would
expect opIndex[string key] to return a JSONValue with .type ==
JSON_TYPE.NULL, but no...

Also If it was returning a JSONValue* it would be easyer to check if a
key is present.

God damn it, how could you miss this design flaw when std.json was
reviewed ?!

JSONValue supports `in`, though:
----
import std.stdio;
import std.json;
void main()
{
    foreach (jsonStr; ["{}", "{\"foo\": 42}"])
    {
        JSONValue jsonObj = parseJSON(jsonStr);
        const JSONValue* p = "foo" in jsonObj;
        if (p is null) writeln("not found");
        else writeln(*p);
    }
}
----

Looks like documentation has been neglected.

Reply via email to