{"record":{"id":"2dd5e2c468cd2cc3","repo":"vectordotdev/vector","slug":"could-not-convert-toml-value-to-json","errorCode":null,"errorMessage":"Could not convert TOML value to JSON","messagePattern":"Could not convert TOML value to JSON","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config/src/external/toml.rs","lineNumber":20,"sourceCode":"\nuse serde_json::Value;\n\nuse crate::{\n    Configurable, GenerateError, ToValue,\n    schema::{SchemaGenerator, SchemaObject},\n};\n\nimpl Configurable for toml::Value {\n    fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> {\n        // `toml::Value` can be anything that it is possible to represent in TOML, and equivalently, is anything it's\n        // possible to represent in JSON, so... a default schema indicates that.\n        Ok(SchemaObject::default())\n    }\n}\n\nimpl ToValue for toml::Value {\n    fn to_value(&self) -> Value {\n        serde_json::to_value(self).expect(\"Could not convert TOML value to JSON\")\n    }\n}\n","sourceCodeStart":2,"sourceCodeEnd":23,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config/src/external/toml.rs#L2-L23","documentation":"`ToValue for toml::Value` converts a TOML config value into a JSON `Value` using serde_json and panics with \"Could not convert TOML value to JSON\" if the conversion fails. Some TOML value shapes (e.g. datetime-local values with mixed offsets, or non-string map keys) are not directly JSON-representable, so the conversion can theoretically fail. Since `to_value` cannot return an error, the failure is a panic.","triggerScenarios":"Generating config schemas or examples from a TOML config containing values whose serde representation serde_json cannot encode — classically TOML datetimes (`1979-05-27T07:32:00`) with no matching JSON serialization, or TOML tables that serialize into non-object shapes.","commonSituations":"Rendering Vector config metadata from user TOML files that include TOML date-time values or exotic key types in tables; version changes in the toml crate altering datetime serialization behavior.","solutions":["Check the TOML source for datetime or exotic-key values and convert them to plain strings before schema generation","If you control the call path, pre-normalize the toml::Value via a recursive conversion that maps Datetime -> String","Ensure the toml crate version in use serializes datetimes to JSON strings, or add a custom Serialize wrapper"],"exampleFix":"// before\nserde_json::to_value(self).expect(\"Could not convert TOML value to JSON\")\n// after\nmatch serde_json::to_value(self) {\n    Ok(v) => v,\n    Err(_) => serde_json::Value::String(self.to_string()),\n}","handlingStrategy":"validation","validationCode":"// Pre-check TOML values for non-JSON-serializable shapes:\nfn toml_to_json_safe(v: &toml::Value) -> Option<serde_json::Value> {\n    serde_json::to_value(v).ok()\n}","typeGuard":"fn is_json_representable(v: &toml::Value) -> bool {\n    !matches!(v, toml::Value::Datetime(_))\n}","tryCatchPattern":"// isolate the conversion:\nlet v = std::panic::catch_unwind(|| toml_value.to_value());","preventionTips":["Convert TOML datetimes to RFC3339 strings in config before schema generation","Avoid non-string table keys in TOML configs","Pin a toml crate version with JSON-safe datetime serialization"],"tags":["rust","toml","json","serialization","panic"],"backgroundTag":"json-serialization-failed","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}