The OpenD Programming Language

serializeToJSONString

Serialize T into a JSON string

@safe
string
serializeToJSONString
(
T
)
(
auto ref T obj
,
in bool pretty = false
)

Examples

struct Test
{
    @serializable int test = 43;
    @serializable string other = "Hello, world";

    @serializable int foo() { return inaccessible; }
    @serializable void foo(int val) { inaccessible = val; }
private:
    int inaccessible = 32;
}

assert(serializeToJSONString(Test()) == `{"foo":32,"other":"Hello, world","test":43}`);

Meta