# Stringifying arbitrary json

**URL:** <https://ziggit.dev/t/stringifying-arbitrary-json/10079>\
**Category:** Help\
**Tags:** standard-library\
**Created:** [May 12, 2025, 7:01pm UTC](https://ziggit.dev/t/stringifying-arbitrary-json/10079 "2025-05-12T19:01:44Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Justus2308](https://ziggit.dev/user_avatar/ziggit.dev/justus2308/32/5305_2.png) [@Justus2308](https://ziggit.dev/u/Justus2308)\
**Post date:** [May 12, 2025, 8:34pm UTC](https://ziggit.dev/t/stringifying-arbitrary-json/10079/2 "2025-05-12T20:34:36Z")

</div>

Hey, welcome to Ziggit!

The problem here is that you’re using the wrong kind of writer.

Zig currently uses implicit interfaces for [readers](https://github.com/ziglang/zig/blob/master/lib/std/io/Reader.zig) and [writers](https://github.com/ziglang/zig/blob/master/lib/std/io/Writer.zig) which can be quite confusing because they’re labeled `anytype` anywhere they’re required as an argument, so basically there’s only the name of the parameter to tell you that a reader or a writer is needed here ([there are plans to change that](https://ziggit.dev/t/the-new-io-abstraction/9404/5)).

However `std.json` has a bunch of specialized readers and writers. This is as of now only indicated by the argument for [`std.json.Value.jsonStringify`](https://github.com/ziglang/zig/blob/bc3c50c21ea3dd902731c1da6bf9b7135eb5b1c1/lib/std/json/dynamic.zig#L63) being called `jws` (JSON write stream) instead of `writer`. The compiler doesn’t complain as much as it probably should here if you use the wrong writer interface because both `std.json.WriteStream` and `std.io.Writer` (which is what `arr.writer()` returns) happen to have a `write` function, however `std.io.Writer.write` indeed only accepts `[]const u8` as a parameter, so if you try to `.write(null)` (which is supported by `std.json.WriteStream.write`) you will get an error.

This means that you have to wrap your `std.ArrayList` writer in a [`std.json.WriteStream`](https://github.com/ziglang/zig/blob/bc3c50c21ea3dd902731c1da6bf9b7135eb5b1c1/lib/std/json/stringify.zig#L102) first before you can supply it to `std.json.Value.jsonStringify` like this:

```zig
[...]
var arr = std.ArrayList(u8).init(allocator);
var jws = std.json.writeStream(arr.writer(), .{});
try parsed.value.jsonStringify(&jws);

```

EDIT: Or just use `std.json.stringify()`, see @stratts reply

---

_[View the full topic](https://ziggit.dev/t/stringifying-arbitrary-json/10079)._
