vectordotdev/vector · error
Serializer does not support JSON
Error message
Serializer does not support JSON
What it means
`Serializer::to_json_value` (lib/codecs/src/encoding/serializer.rs:460) panics for codecs that have no structured JSON representation: Avro, Cef, Csv, Logfmt, Text, Native, Protobuf and RawMessage. Only Gelf, Json and NativeJson can encode an event to a `serde_json::Value`. The enum exposes `Serializer::supports_json()` (serializer.rs:436) so callers can check the capability at runtime; the `# Panics` section of the method documents this contract. In-tree callers such as the Splunk HEC logs encoder (src/sinks/splunk_hec/logs/encoder.rs:90) always guard with `supports_json()` before calling `to_json_value`.
Source
Thrown at lib/codecs/src/encoding/serializer.rs:473
///
/// # Panics
///
/// Panics if the serializer does not support encoding to JSON. Call `Serializer::supports_json`
/// if you need to determine the capability to encode to JSON at runtime.
pub fn to_json_value(&self, event: Event) -> Result<serde_json::Value, vector_common::Error> {
match self {
Serializer::Gelf(serializer) => serializer.to_json_value(event),
Serializer::Json(serializer) => serializer.to_json_value(event),
Serializer::NativeJson(serializer) => serializer.to_json_value(event),
Serializer::Avro(_)
| Serializer::Cef(_)
| Serializer::Csv(_)
| Serializer::Logfmt(_)
| Serializer::Text(_)
| Serializer::Native(_)
| Serializer::Protobuf(_)
| Serializer::RawMessage(_) => {
panic!("Serializer does not support JSON")
}
#[cfg(feature = "syslog")]
Serializer::Syslog(_) => {
panic!("Serializer does not support JSON")
}
#[cfg(feature = "opentelemetry")]
Serializer::Otlp(_) => {
panic!("Serializer does not support JSON")
}
}
}
/// Returns the chunking implementation for the serializer, if any is supported.
pub fn chunker(&self) -> Option<Chunker> {
match self {
Serializer::Gelf(gelf) => Some(Chunker::Gelf(gelf.chunker())),
_ => None,
}View on GitHub (pinned to 3708c39b12)
Solutions
- Call `serializer.supports_json()` before `to_json_value` and fall back to `serializer.encode(event, &mut bytes)` (byte framing) when it returns false, mirroring src/sinks/splunk_hec/logs/encoder.rs:90-99.
- Change the sink's encoding config to a JSON-capable codec: `encoding.codec = "json"` (or `native_json`/`gelf`).
- If structured output is mandatory for your component, reject non-JSON codecs at config-load time with a configuration error instead of panicking at runtime.
Example fix
// before
let json = serializer.to_json_value(event); // panics when codec is text/csv/avro/...
// after
let payload = if serializer.supports_json() {
Payload::Json(serializer.to_json_value(event)?)
} else {
let mut bytes = BytesMut::new();
serializer.encode(event, &mut bytes)?;
Payload::Text(bytes.to_vec())
}; Defensive patterns
Strategy: validation
Validate before calling
if !serializer.supports_json() {
// fall back to byte encoding; do not call to_json_value
}
let json = serializer.to_json_value(event)?; Type guard
fn is_json_capable(s: &Serializer) -> bool {
s.supports_json() // true only for Json, NativeJson, Gelf
} Prevention
- Treat supports_json() as a mandatory pre-condition everywhere to_json_value is reachable from user configuration.
- Mirror the pattern in src/sinks/splunk_hec/logs/encoder.rs:90 — JSON path when supported, encode() path otherwise.
- Add unit tests covering both a JSON-capable and a non-JSON codec for every code path that calls to_json_value.
- Prefer encode() (bytes) as the default integration surface; use to_json_value only where structured values are truly required.
When it happens
Trigger: Calling `serializer.to_json_value(event)` on a `Serializer` built from `AvroSerializerConfig`, `CefSerializerConfig`, `CsvSerializerConfig`, `LogfmtSerializerConfig`, `TextSerializerConfig`, `NativeSerializerConfig`, `ProtobufSerializerConfig` or `RawMessageSerializerConfig`. Typically this happens in custom sinks or transforms that store a user-configured `Serializer` and unconditionally try to get structured JSON, e.g. building a `HecEvent::Json` payload or preparing rows for Postgres/Parquet with a `encoding.codec = "text"` or `"avro"` codec.
Common situations: Embedding vector-lib codecs in a custom sink whose framing wants JSON objects; a config change from `encoding.codec = "json"` to `"csv"`/`"logfmt"`/`"text"` in a pipeline whose downstream code path assumed JSON; upgrading Vector and newly enabling a codec variant that reaches an unguarded `to_json_value` call site.
Related errors
- path and query should never fail to parse
- Paths must always start with a leading forward slash (`/`).
- Only leaf nodes should be allowed to be non-object values.
- Reader encountered unrecoverable error: {e:?}
- Key is not found: {:?}
AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20).
Data as JSON: /api/errors/3ee0ba2368e2f7b8.
Report an issue: GitHub.