www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - I can't believe this !!

reply MesmerizedInTheMorning <MesmerizedInTheMorning hkl.hkl.hkl.fu> writes:
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 ?!
Nov 13 2015
next sibling parent Rikki Cattermole <alphaglosined gmail.com> writes:
On 14/11/15 7:30 PM, 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 ?!
in overload was introduced to JsonValue in 2.066.0 and it is still there. https://github.com/D-Programming-Language/dlang.org/blob/cbb94142ac52e9c57648b10708aedfa55711fe47/changelog/2.066.0.dd#L1042 As per the unittest: /// unittest { JSONValue j = [ "language": "D", "author": "walter" ]; string a = ("author" in j).str; } https://github.com/D-Programming-Language/phobos/blob/master/std/json.d#L538
Nov 13 2015
prev sibling parent reply anonymous <anonymous example.com> writes:
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.
Nov 13 2015
parent MesmerizedInTheMorning <MesmerizedInTheMorning hkl.hkl.hkl.fu> writes:
On Saturday, 14 November 2015 at 06:51:14 UTC, anonymous wrote:
 On 14.11.2015 07:30, MesmerizedInTheMorning wrote:
 [...]
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.
What a relief...I should look at the source closer. I guess that the issue should be closed with RESOLVED INVALID.
Nov 13 2015