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)), } }