JSONValue.emptyOrderedObject

An enum value that can be used to obtain a JSONValue representing an empty JSON object. Unlike emptyObject, the order of inserted keys is preserved.

struct JSONValue
enum emptyOrderedObject = ();

Examples

JSONValue obj = JSONValue.emptyOrderedObject;
assert(obj.type == JSONType.object);
assert(obj.isOrdered);
obj["b"] = JSONValue(2);
obj["a"] = JSONValue(1);
assert(obj["a"] == JSONValue(1));
assert(obj["b"] == JSONValue(2));

string[] keys;
foreach (string k, JSONValue v; obj)
    keys ~= k;
assert(keys == ["b", "a"]);

Meta