From f9443c31c179170b35f04231d8aad988a026c850 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 9 Aug 2026 16:33:10 -0700 Subject: [PATCH] stringify: support null type --- json.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/json.zig b/json.zig index 29ff9007315fb9d6dabbb88472658a0849b04a2c..96ad9513731b900b6223c396f9304cc93ad40d2c 100644 --- a/json.zig +++ b/json.zig @@ -799,7 +799,7 @@ pub fn stringify(writer: anytype, value: anytype, options: std.json.Stringify.Op try writer.writeAll("{"); inline for (info.fields, 0..) |field, i| blk: { const field_value = @field(value, field.name); - if (@typeInfo(field.type) == .optional and field_value == null and !options.emit_null_optional_fields) break :blk; + if (((@typeInfo(field.type) == .optional and field_value == null) or @typeInfo(field.type) == .null) and !options.emit_null_optional_fields) break :blk; if (i > 0) try writer.writeAll(","); try stringify(writer, field.name, options); try writer.writeAll(":"); @@ -840,6 +840,9 @@ pub fn stringify(writer: anytype, value: anytype, options: std.json.Stringify.Op .@"enum" => { try T.stringifyJson(value, writer, options, @This()); }, + .null => { + try writer.writeAll("null"); + }, else => @compileError(@typeName(T)), } } -- 2.54.0