# std.json: expose encodeJsonString and encodeJsonStringChars · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/f598234ee820ca0d57946542a852f193b21d847f)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: f598234ee820ca0d57946542a852f193b21d847f

Requested commit: f598234ee820ca0d57946542a852f193b21d847f

Commit: f598234ee820ca0d57946542a852f193b21d847f

Tree: 5ab1dda8719c06cd4b52e2b7ce7c8f0c4b8f417a

Author: Jonathan Marler

Committer: Veikka Tuominen

## Message

```
std.json: expose encodeJsonString and encodeJsonStringChars

Expose 2 functions from std.json.  These functions take a slice of bytes
and forward them to a given writer as a JSON encoded string.

The use case I have for this is in a custom JsonStringWriter.  This writer
takes data and automatically encodes it as JSON string characters and
forwards it to an underlying writer.  I use this JsonStringWriter in
combination with std.fmt.format to go directly from a format string/arg
pair to JSON.  This way I don't have to format my string into a separate
buffer first and encode it afterwards, which avoids the need to create
a temporary buffer to hold the unencoded but formatted string.

```

## Parents

- [a2ab9e36faded9755ecc1fe809c49140120c3c61](https://git.cafe/gitcafe/zig/commit/a2ab9e36faded9755ecc1fe809c49140120c3c61?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/f598234ee820ca0d57946542a852f193b21d847f?format=markdown)
