From 80e943ac8734b91da3560c8f45bbe702d833ac11 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 24 May 2026 03:42:04 -0700 Subject: [PATCH] add stringifyAlloc --- json.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/json.zig b/json.zig index 4f77bf0d04760313c5eee99a71f5874d14219634..d1866f89f32fe299156b4b82370951afcc3446b6 100644 --- a/json.zig +++ b/json.zig @@ -765,3 +765,11 @@ pub fn stringify(writer: anytype, value: anytype, options: std.json.StringifyOpt else => @compileError(@typeName(T)), } } + +pub fn stringifyAlloc(allocator: std.mem.Allocator, value: anytype, options: std.json.StringifyOptions) ![]u8 { + var writer: nio.AllocatingWriter = .init(allocator); + defer writer.deinit(); + try writer.ensureUnusedCapacity(256); + try stringify(&writer, value, options); + return writer.toOwnedSlice(); +} -- 2.54.0