serializeValue

Input range serialization

Examples

input range serialization

import std.algorithm : filter;

struct Foo
{
    int i;
}

auto ar = [Foo(1), Foo(3), Foo(4), Foo(17)];

auto filtered1 = ar.filter!"a.i & 1";
auto filtered2 = ar.filter!"!(a.i & 1)";

assert(serializeToJson(filtered1) == `[{"i":1},{"i":3},{"i":17}]`);
assert(serializeToJson(filtered2) == `[{"i":4}]`);
uint[2] ar = [1, 2];
assert(serializeToJson(ar) == `[1,2]`);
assert(serializeToJson(ar[]) == `[1,2]`);
assert(serializeToJson(ar[0 .. 0]) == `[]`);
assert(serializeToJson((uint[]).init) == `null`);

Meta