Bool setter for std.json

w0rp devw0rp at gmail.com
Mon Feb 24 10:57:51 PST 2014


On Monday, 24 February 2014 at 18:33:49 UTC, Adam D. Ruppe wrote:
> On Monday, 24 February 2014 at 18:22:43 UTC, monarch_dodra 
> wrote:
>> Why does the JSON_TYPE enum have "TRUE" and "FALSE" to begin 
>> with? Shouldn't it just be a single "BOOLEAN" type with two 
>> values?
>
> The json spec lists true, false, and null as distinct values:
> http://www.json.org/
>
>
> My guess is that since they are represented by javascript 
> keywords (and come from the weakly-typed language), this makes 
> the lexer and parser implementation match right up the 
> JSON_TYPE thing.
>
> so I don't really know, but the 1-1 correspondence with the 
> keywords kinda makes sense to me.

typeof(false) === "boolean" in JavaScript. There is a boolean 
type in JavaScript. It really should just be "BOOLEAN" in 
std.json.

I don't mean to show off or anything dumb like that, but I 
haven't used std.json for a while after I wrote my own library, 
which I tweaked until it was as efficient as std.json at what it 
does and hopefully bug free. (I have many test cases, and 
anything I missed I'll add more cases for.)

https://github.com/w0rp/dson/blob/master/json.d

JSON x; // x.isNull
x = true; // opAssign is specified in addition to constructors
x = false; // x.type == JSON_TYPE.BOOLEAN or just x.isBool
x = 3; // x.isNumber
x = null; // x.isNull
x = jsonArray(); // x.isArray
x = jsonObject(); // x.isObject

It goes on like that. I think std.json should have similar 
behaviour, because things can be a lot easier.


More information about the Digitalmars-d mailing list