authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-02-25 20:37:48+11:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-04-01 00:12:59+11:00
loga32d88f12c65b48c8861748f0879bcb1b5be61d0
tree342397fe9c5187c2b269ac311f7616c10c8c2675
parent62fbb6b87406d8dd0b256ca42246b86972cd2faf
signaturelock-open Commit is signed but in an unrecognized format.

std: add support to std.json.stringify for null literals


1 files changed, 5 insertions(+), 2 deletions(-)

lib/std/json.zig+5-2
...@@ -1239,7 +1239,7 @@ pub const Value = union(enum) {...@@ -1239,7 +1239,7 @@ pub const Value = union(enum) {
1239 out_stream: var,1239 out_stream: var,
1240 ) @TypeOf(out_stream).Error!void {1240 ) @TypeOf(out_stream).Error!void {
1241 switch (value) {1241 switch (value) {
1242 .Null => try out_stream.writeAll("null"),1242 .Null => try stringify(null, options, out_stream),
1243 .Bool => |inner| try stringify(inner, options, out_stream),1243 .Bool => |inner| try stringify(inner, options, out_stream),
1244 .Integer => |inner| try stringify(inner, options, out_stream),1244 .Integer => |inner| try stringify(inner, options, out_stream),
1245 .Float => |inner| try stringify(inner, options, out_stream),1245 .Float => |inner| try stringify(inner, options, out_stream),
...@@ -2414,11 +2414,14 @@ pub fn stringify(...@@ -2414,11 +2414,14 @@ pub fn stringify(
2414 .Bool => {2414 .Bool => {
2415 return out_stream.writeAll(if (value) "true" else "false");2415 return out_stream.writeAll(if (value) "true" else "false");
2416 },2416 },
2417 .Null => {
2418 return out_stream.writeAll("null");
2419 },
2417 .Optional => {2420 .Optional => {
2418 if (value) |payload| {2421 if (value) |payload| {
2419 return try stringify(payload, options, out_stream);2422 return try stringify(payload, options, out_stream);
2420 } else {2423 } else {
2421 return out_stream.writeAll("null");2424 return try stringify(null, options, out_stream);
2422 }2425 }
2423 },2426 },
2424 .Enum => {2427 .Enum => {