#26514·vector

`json` codec: option to encode byte values as base64

Author: Danielku15Created Sep 30, 2026Updated Sep 30, 2026

A note for the community

  • Please vote on this issue by adding a reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Use Cases

We use Vector to archive raw byte data streams. The streams arrive over WebSocket as binary frames. the websocket source turns each frame into one event with the raw bytes in message. The same events go to two sinks:

  • a NATS sink, which forwards the raw bytes;
  • an azure_blob sink (blob_type: append) that writes newline-delimited JSON with zstd compression, one line per frame with its receive timestamp.

The archive has to be lossless: a replay tool must be able to recover every frame byte for byte from message. The frames have to stay binary (we don't control the producer), the archive has to stay NDJSON, and we want to avoid a per-event VRL transform, since this runs for about 600 streams.

The json codec can't do this today. It writes byte values as UTF-8 and replaces every invalid sequence with U+FFFD, so binary payloads are silently corrupted in the archive.

Attempted Solutions

codec: json

yaml
sources:
  ws:
    type: websocket
    uri: ws://gnss-server/
sinks:
  archive:
    type: console
    inputs: [ws]
    encoding:
      codec: json

The binary frame d3 00 04 3e d0 80 ff is written as:

{"message":"�\u0000\u0004>Ѐ�","source_type":"websocket","timestamp":"2026-09-30T10:49:14.306264900Z"}

The message bytes are ef bf bd 00 04 3e d0 80 ef bf bd: d3 and ff became U+FFFD and can't be recovered. A real 48-byte RTCM chunk became 82 bytes containing 17 replacement characters. Text frames round-trip unchanged.

To reproduce without a WebSocket server, use . = { "message": decode_base64!("0wAEPtCA/w==") } in a remap in front of a json sink. It prints {"message":"�\u0000\u0004>Ѐ�"}.

codec: native_json

Lossy in the same way: {"log":{"message":"�\u0000\u0004>Ѐ�"}}.

remap with encode_base64

yaml
transforms:
  archive_base64:
    type: remap
    inputs: [ws]
    source: |
      .message = encode_base64!(.message)

This gives the right output ({"message":"0wAEPtCA/w==",...}), but it runs VRL on every event only to change how one field is serialized. It also has to sit on the archive path alone, because the NATS sink needs the raw bytes.

Other options

  • native and protobuf keep the bytes, but their output isn't NDJSON.
  • raw_message with length_delimited framing keeps the bytes, but isn't NDJSON and drops the timestamp.
  • Text frames from the producer aren't possible: we don't control its protocol, and text frames must be valid UTF-8, so the data would have to be base64-encoded upstream, which breaks the raw NATS consumers.

Proposal

Add an option to the json serializer, next to pretty, that controls how byte values are written:

yaml
encoding:
  codec: json
  json:
    bytes: base64 # default: lossy_utf8
  • lossy_utf8 (default): the current behavior.
  • base64: every byte value is written as a base64 string (RFC 4648 standard alphabet, padded, the same as VRL's encode_base64), at any depth in objects and arrays. Keys, all other value types, key order, and compact and pretty output are unchanged.

With bytes: base64, the frame above becomes:

{"message":"0wAEPtCA/w==","source_type":"d2Vic29ja2V0","timestamp":"2026-09-30T10:49:14.306264900Z"}

The conversion happens only in the encoder, so other sinks reading the same events still get the raw bytes. It would apply to log and trace events, and also to JsonSerializer::to_json_value (used by the splunk_hec logs sink). Metric events contain no byte values.

One point I'm unsure about: VRL has no separate string type, so base64 applies to all string values (see source_type above), not only binary ones. That is fine for our use case. If you'd rather limit it to selected fields (for example a list of paths), I can do that instead. Encoding only the values that aren't valid UTF-8 wouldn't work, because a reader couldn't tell text from base64. The option name is open too.

native_json is out of scope, since #26281 changes its format.

I'm happy to implement this once the approach is agreed.

References

  • #11577: RFC on handling (non-UTF-8) byte payloads in Vector and VRL
  • #1377: split the Bytes type into strings and raw bytes
  • #26281: base native_json on Protobuf (bytes become base64 rawBytes inside a Protobuf envelope)
  • #24252 (discussion) and #24595: binary data in the ClickHouse sink
  • #19434 (discussion): protobuf bytes fields in JSON output
  • #10571: audit usages of String::from_utf8

Version

vector 0.58.0 (x86_64-unknown-linux-gnu 2bcad9b 2026-08-26 13:37:07.557544670)