From 259c22999c14345222992b7cb4d06e1a3e76cadc Mon Sep 17 00:00:00 2001 From: torque Date: Fri, 8 Mar 2024 10:50:21 -0800 Subject: [PATCH] example: output JSON this works a lot better than the very bad dump function I had before. The output isn't pretty printed but can easily be made so by piping it to jq, for example. --- example/main.zig | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/example/main.zig b/example/main.zig index 10d7201..6fd6160 100644 --- a/example/main.zig +++ b/example/main.zig @@ -27,27 +27,5 @@ pub fn main() !void { }; defer doc.deinit(); - std.debug.print("\n-----\n\n", .{}); - - dump(doc.root); -} - -fn dump(val: yaml.Value) void { - switch (val) { - .scalar => |str| std.debug.print("scalar: {s}\n", .{str}), - .list => |list| { - std.debug.print("list: \n", .{}); - for (list) |item| dump(item); - std.debug.print("end list\n", .{}); - }, - .map => |map| { - std.debug.print("map: \n", .{}); - var iter = map.iterator(); - while (iter.next()) |entry| { - std.debug.print("key: {s}\n", .{entry.key_ptr.*}); - dump(entry.value_ptr.*); - } - std.debug.print("end map\n", .{}); - }, - } + try std.json.stringify(doc.root, .{}, std.io.getStdOut().writer()); }