Serialization Example

First import ziggy (see Getting Started to learn how to add Ziggy as a dependency):

const ziggy = @import("ziggy");

Serializing

ziggy.serialize is the function that turns a Zig value into a Ziggy document.

Usage is extremely straight-forward, just make sure to read the relative doc comments.

In case you want to serialize a value but keep it in memory, you can use std.Io.Writer.Allocating:

var out: std.Io.Writer.Allocating = .init(gpa);
defer out.deinit();

try ziggy.serialize(foo, .{}, output_buffer.writer());

The second parameter of the function can be used to configure the Serializer, its type is ziggy.Serializer.Options

To get our result, simply read from out.written()

std.debug.print("{s}\n", .{out.written()});