authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-09 16:33:10-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-09 16:33:10-07:00
logf9443c31c179170b35f04231d8aad988a026c850
treea90322a2e7bccd35176be4591bc078a3339684a9
parent7f12aa0cf95430f318ddf49e9dd7f9722b31d542
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

stringify: support null type


1 files changed, 4 insertions(+), 1 deletions(-)

json.zig+4-1
......@@ -799,7 +799,7 @@ pub fn stringify(writer: anytype, value: anytype, options: std.json.Stringify.Op
799799 try writer.writeAll("{");
800800 inline for (info.fields, 0..) |field, i| blk: {
801801 const field_value = @field(value, field.name);
802 if (@typeInfo(field.type) == .optional and field_value == null and !options.emit_null_optional_fields) break :blk;
802 if (((@typeInfo(field.type) == .optional and field_value == null) or @typeInfo(field.type) == .null) and !options.emit_null_optional_fields) break :blk;
803803 if (i > 0) try writer.writeAll(",");
804804 try stringify(writer, field.name, options);
805805 try writer.writeAll(":");
......@@ -840,6 +840,9 @@ pub fn stringify(writer: anytype, value: anytype, options: std.json.Stringify.Op
840840 .@"enum" => {
841841 try T.stringifyJson(value, writer, options, @This());
842842 },
843 .null => {
844 try writer.writeAll("null");
845 },
843846 else => @compileError(@typeName(T)),
844847 }
845848}