`stringify()` is gone

Release notes do not cover json at all, and Stringify is missing new()/init()/etc. Wrestling with this for couple days now without success:

src/util.zig:26:21: error: root source file struct 'json' has no member named 'stringify'
        try std.json.stringify(self, .{}, stdout);

It’s now available via std.json.Stringify (usage example).

// v0.15.dev

    const out_buffer: []u8 = try allocator.alloc(u8, 4096000);
    defer allocator.free(out_buffer);
    var fixed_writer: std.Io.Writer = .fixed(out_buffer);
    var w: std.json.Stringify = .{ .writer = &fixed_writer, .options = .{ .whitespace = .indent_2 }};

@gbjark @JPL thanks! I ended up with this but idk yet if its going to work since I need to resolve http and arrays first:

pub fn json(
    self: *Counter,
    stdout: @TypeOf(std.io.getStdOut().writer()),
) !void {
    const options = std.json.StringifyOptions{};
    try std.json.stringify(self, options, stdout);
}

:down_arrow:

pub fn json(
    self: *Counter,
    stdout: *std.Io.Writer,
) !void {
    var sj: std.json.Stringify = .{ .writer = stdout, .options = .{} };
    try sj.write(self);
}
2 Likes