{"record":{"id":"3ee0ba2368e2f7b8","repo":"vectordotdev/vector","slug":"serializer-does-not-support-json","errorCode":null,"errorMessage":"Serializer does not support JSON","messagePattern":"Serializer does not support JSON","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/codecs/src/encoding/serializer.rs","lineNumber":473,"sourceCode":"    ///\n    /// # Panics\n    ///\n    /// Panics if the serializer does not support encoding to JSON. Call `Serializer::supports_json`\n    /// if you need to determine the capability to encode to JSON at runtime.\n    pub fn to_json_value(&self, event: Event) -> Result<serde_json::Value, vector_common::Error> {\n        match self {\n            Serializer::Gelf(serializer) => serializer.to_json_value(event),\n            Serializer::Json(serializer) => serializer.to_json_value(event),\n            Serializer::NativeJson(serializer) => serializer.to_json_value(event),\n            Serializer::Avro(_)\n            | Serializer::Cef(_)\n            | Serializer::Csv(_)\n            | Serializer::Logfmt(_)\n            | Serializer::Text(_)\n            | Serializer::Native(_)\n            | Serializer::Protobuf(_)\n            | Serializer::RawMessage(_) => {\n                panic!(\"Serializer does not support JSON\")\n            }\n            #[cfg(feature = \"syslog\")]\n            Serializer::Syslog(_) => {\n                panic!(\"Serializer does not support JSON\")\n            }\n            #[cfg(feature = \"opentelemetry\")]\n            Serializer::Otlp(_) => {\n                panic!(\"Serializer does not support JSON\")\n            }\n        }\n    }\n\n    /// Returns the chunking implementation for the serializer, if any is supported.\n    pub fn chunker(&self) -> Option<Chunker> {\n        match self {\n            Serializer::Gelf(gelf) => Some(Chunker::Gelf(gelf.chunker())),\n            _ => None,\n        }","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/codecs/src/encoding/serializer.rs#L455-L491","documentation":"`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`.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlet json = serializer.to_json_value(event); // panics when codec is text/csv/avro/...\n\n// after\nlet payload = if serializer.supports_json() {\n    Payload::Json(serializer.to_json_value(event)?)\n} else {\n    let mut bytes = BytesMut::new();\n    serializer.encode(event, &mut bytes)?;\n    Payload::Text(bytes.to_vec())\n};","handlingStrategy":"validation","validationCode":"if !serializer.supports_json() {\n    // fall back to byte encoding; do not call to_json_value\n}\nlet json = serializer.to_json_value(event)?;","typeGuard":"fn is_json_capable(s: &Serializer) -> bool {\n    s.supports_json() // true only for Json, NativeJson, Gelf\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["rust","vector","codecs","serializer","json","panic"],"backgroundTag":"unsupported-serialization-format","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}