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;


Reply via email to