Create an empty json object with std.json

Andrea Fontana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 22 03:53:11 PST 2016


If you declare a JSONValue like this:

JSONValue json;

then:

assert(json.type() == JSON_TYPE.NULL);

Documentation at 
https://dlang.org/phobos/std_json.html#.JSONValue.type.2 suggests 
not to change type but to assign a new value instead.

My problem is: how can I assign an empty object like {}?

The only way i found is using that deprecated method:
json.type = JSON_TYPE.OBJECT;

or

json = `{}`.parseJSON;

Please notice that to init as array this works:
json = JSONValue[].init;




More information about the Digitalmars-d-learn mailing list