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.
This commit is contained in:
torque 2024-03-08 10:50:21 -08:00
parent ab0202a5f7
commit 259c22999c
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk

View File

@ -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());
}