toJson

Serialize T to JSON, and return the result as a string.

string
toJson
(
T
)
(
T v
)

Examples

struct X { int a; string b; }
X x = {17, "aoeu"};
assert(toJson(x) == `{"a":17,"b":"aoeu"}`, toJson(x));
int[] arr = [1,5,7];
assert(toJson(arr) == `[1,5,7]`);
assert(toJson(true) == `true`);

assert(toJson(tuple()) == ``);
assert(toJson(tuple(42)) == `42`);
assert(toJson(tuple(42, "banana")) == `[42,"banana"]`);

Meta