DoxigAlpha

jsonStringify

Function parameters

Parameters

#
value:@This()
jws:anytype

Represents any JSON value, potentially containing other JSON values.

Types

#
Value
Represents any JSON value, potentially containing other JSON values.

Source

Implementation

#
pub fn jsonStringify(value: @This(), jws: anytype) !void {
    switch (value) {
        .null => try jws.write(null),
        .bool => |inner| try jws.write(inner),
        .integer => |inner| try jws.write(inner),
        .float => |inner| try jws.write(inner),
        .number_string => |inner| try jws.print("{s}", .{inner}),
        .string => |inner| try jws.write(inner),
        .array => |inner| try jws.write(inner.items),
        .object => |inner| {
            try jws.beginObject();
            var it = inner.iterator();
            while (it.next()) |entry| {
                try jws.objectField(entry.key_ptr.*);
                try jws.write(entry.value_ptr.*);
            }
            try jws.endObject();
        },
    }
}