lu.json

Simple JSON wrappers around Phobos' std.json to make keeping JSON storages easier. This is not a replacement for std.json; it merely extends it.

Members

Functions

populateFromJSON
void populateFromJSON(T target, JSONValue json, bool lowercaseKeys, bool lowercaseValues)

Recursively populates a passed associative or dynamic array with the contents of a JSONValue.

Structs

JSONStorage
struct JSONStorage

A wrapped JSONValue with helper functions.

Examples

JSONStorage json;
assert(json.storage.type == JSONType.null_);

json.load("somefile.json");
assert(json.storage.type == JSONType.object);

json.serialiseInto!(JSONStorage.KeyOrderStrategy.inGivenOrder)
    (stdout.lockingTextWriter, [ "foo", "bar", "baz" ]);

// Printed to screen, regardless how `.toPrettyString` would have ordered it:
/*
    {
        "foo": {
            1,
            2,
        },
        "bar": {
            3,
            4,
        },
        "baz": {
            5,
            6,
        }
    }
*/

// Prints keys in sorted order.
json.serialiseInto!(JSONStorage.KeyOrderStrategy.sorted)(stdout.lockingTextWriter)

// Use a [std.array.Appender|Appender] to serialise into a string.

// Adding and removing values still needs the same dance as with std.json.
// Room for future improvement.
json.storage["qux"] = null;
json.storage["qux"].array = null;
json.storage["qux"].array ~= 7;
json.storage["qux"].array ~= 8;

json.save("somefile.json");

Meta