From 98b0c4127f16b0501b4073bd54b75959526df931 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Thu, 2 Sep 2021 15:41:14 -0700 Subject: [PATCH] add generic dump function - handy for printf debugging --- src/json.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/json.zig b/src/json.zig index 58aa632..9934069 100644 --- a/src/json.zig +++ b/src/json.zig @@ -1324,6 +1324,14 @@ pub const Value = union(enum) { } }; +pub fn dump(value: anytype) void { + var held = std.debug.getStderrMutex().acquire(); + defer held.release(); + + const stderr = std.io.getStdErr().writer(); + std.json.stringify(value, std.json.StringifyOptions{ .whitespace = null }, stderr) catch return; +} + test "Value.jsonStringify" { { var buffer: [10]u8 = undefined;