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:
parent
ab0202a5f7
commit
259c22999c
@ -27,27 +27,5 @@ pub fn main() !void {
|
|||||||
};
|
};
|
||||||
defer doc.deinit();
|
defer doc.deinit();
|
||||||
|
|
||||||
std.debug.print("\n-----\n\n", .{});
|
try std.json.stringify(doc.root, .{}, std.io.getStdOut().writer());
|
||||||
|
|
||||||
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", .{});
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user