diff --git a/lib/std/json/stringify.zig b/lib/std/json/stringify.zig index 9bc0e564a1ad..2564318fbd51 100644 --- a/lib/std/json/stringify.zig +++ b/lib/std/json/stringify.zig @@ -670,6 +670,9 @@ pub fn WriteStream( const array: [info.len]info.child = value; return self.write(&array); }, + .type => { + return self.stringValue(@typeName(value)); + }, else => @compileError("Unable to stringify type '" ++ @typeName(T) ++ "'"), } unreachable; diff --git a/lib/std/json/stringify_test.zig b/lib/std/json/stringify_test.zig index 52e38d1e30ad..986fd1e25a25 100644 --- a/lib/std/json/stringify_test.zig +++ b/lib/std/json/stringify_test.zig @@ -415,6 +415,15 @@ test "comptime stringify" { MyStruct{ .foo = 100 }, MyStruct{ .foo = 1000 }, }, .{}, 8) catch unreachable; + + const MyStruct2 = struct { + type: type, + }; + comptime testStringifyMaxDepth("[{\"type\":\"u1\"},{\"type\":\"[]const u8\"},{\"type\":\"anyopaque\"}]", [_]MyStruct2{ + MyStruct2{ .type = u1 }, + MyStruct2{ .type = []const u8 }, + MyStruct2{ .type = anyopaque }, + }, .{}, null) catch unreachable; } test "print" {