Commit a32d88f12c

daurnimator <quae@daurnimator.com>
2020-02-25 10:37:48
std: add support to std.json.stringify for null literals
1 parent 62fbb6b
Changed files (1)
lib
lib/std/json.zig
@@ -1239,7 +1239,7 @@ pub const Value = union(enum) {
         out_stream: var,
     ) @TypeOf(out_stream).Error!void {
         switch (value) {
-            .Null => try out_stream.writeAll("null"),
+            .Null => try stringify(null, options, out_stream),
             .Bool => |inner| try stringify(inner, options, out_stream),
             .Integer => |inner| try stringify(inner, options, out_stream),
             .Float => |inner| try stringify(inner, options, out_stream),
@@ -2414,11 +2414,14 @@ pub fn stringify(
         .Bool => {
             return out_stream.writeAll(if (value) "true" else "false");
         },
+        .Null => {
+            return out_stream.writeAll("null");
+        },
         .Optional => {
             if (value) |payload| {
                 return try stringify(payload, options, out_stream);
             } else {
-                return out_stream.writeAll("null");
+                return try stringify(null, options, out_stream);
             }
         },
         .Enum => {