https://issues.dlang.org/show_bug.cgi?id=15410
[email protected] changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |[email protected] Resolution|--- |INVALID --- Comment #1 from [email protected] --- (In reply to Chris Wright from comment #0) > opIndex(string) says: > > "Throws JSONException if type is not JSON_TYPE.OBJECT." > > This implies the correct way to create a JSONValue of type OBJECT, assuming > you don't want to use an AA literal, is: > > [...] > > However! The documentation is actually wrong! I can just write: > > --- > JSONValue j; > j["key"] = "value"; > --- > > That works! The documentation told me it would throw an exception, so there > was no reason for me to try it. It was guaranteed to me that it would fail. > But instead it succeeded. Your report is invalid. You say that 'opIndex(string)' ddoc specifies that it throws. But what you call is not opIndex(), it's opIndexAssign()!!! And 'opIndexAssign' ddoc says: /// Operator sets value for element of JSON object by key. /// If JSON value is null, then operator initializes it with object and then /// sets value for it. /// Throws JSONException if type is not JSON_TYPE.OBJECT or JSON_TYPE.NULL Your 'j' is initially null, then the call to opIndexASsign initializes j as a JSONObject. --
