{"record":{"id":"41cdfa4535d9c924","repo":"pola-rs/polars","slug":"writing-to-json","errorCode":null,"errorMessage":"Writing {:?} to JSON","messagePattern":"Writing (.+?) to JSON","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-json/src/json/write/serialize.rs","lineNumber":634,"sourceCode":"                convert,\n                offset,\n                take,\n            )\n        },\n        ArrowDataType::Time64(tu) => {\n            let convert = match tu {\n                TimeUnit::Nanosecond => time64ns_to_time,\n                tu => panic!(\"Invalid time unit '{tu:?}' for Time.\"),\n            };\n            time_serializer(\n                array.as_any().downcast_ref().unwrap(),\n                convert,\n                offset,\n                take,\n            )\n        },\n        ArrowDataType::Null => null_serializer(array.len(), offset, take),\n        other => todo!(\"Writing {:?} to JSON\", other),\n    }\n}\n\nfn serialize_item<'a>(\n    buffer: &mut Vec<u8>,\n    record: impl Iterator<Item = (&'a str, &'a [u8])>,\n    is_first_row: bool,\n) {\n    if !is_first_row {\n        buffer.push(b',');\n    }\n    buffer.push(b'{');\n    let mut first_item = true;\n    for (key, value) in record {\n        if !first_item {\n            buffer.push(b',');\n        }\n        first_item = false;","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-json/src/json/write/serialize.rs#L616-L652","documentation":"The serializer's match over ArrowDataType is exhaustive only for types polars-json supports; anything else reaches `todo!(\"Writing {:?} to JSON\", other)`, which panics with a not-yet-implemented message naming the type. It marks an unimplemented serialization path, not corrupt data.","triggerScenarios":"Passing a DataFrame/column containing an Arrow data type polars-json cannot serialize yet (e.g. Interval, FixedSizeBinary, Union, Dictionary depending on version) into the JSON writer via new/serialize/serialize_to_utf8 or nested struct/list serializers.","commonSituations":"Serializing data produced by other Arrow tooling with exotic types; upgrading arrow crates introduces a new type that flows through untyped channels; users constructing unusual schemas manually.","solutions":["Cast unsupported columns to a JSON-compatible type (String, Int64, Float64, etc.) before writing.","Drop the unsupported column from the DataFrame before serialization.","Implement the missing serializer arm in crates/polars-json/src/json/write/serialize.rs if you own the build.","Upgrade polars — the todo may be implemented in a newer release."],"exampleFix":"// before\nlet df: DataFrame = ...; // contains Interval column\nwriter.serialize(&df);\n// after\nlet df = df.drop(\"interval_col\").unwrap(); // or cast to a supported type\nwriter.serialize(&df);","handlingStrategy":"validation","validationCode":"const JSON_SERIALIZABLE: &[ArrowDataType] = &[\n    ArrowDataType::Null, ArrowDataType::Boolean, ArrowDataType::Int64, ArrowDataType::Float64,\n    ArrowDataType::Utf8, ArrowDataType::LargeUtf8, /* ... supported set for your polars version */\n];\n// verify each column's dtype against the supported set (or try a cast fallback) before writing","typeGuard":"fn is_json_supported(dt: &ArrowDataType) -> bool {\n    !matches!(dt, ArrowDataType::Interval(_) | ArrowDataType::Union(_, _) | ArrowDataType::FixedSizeBinary(_))\n}","tryCatchPattern":"// panics are not catchable via Result; use catch_unwind if you must survive foreign schemas\nlet result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| writer.serialize(&df)));\nif result.is_err() { /* fall back to dropping/casting exotic columns */ }","preventionTips":["Whitelist column dtypes before writing JSON.","Cast exotic types (Interval, Union, Dictionary) to primitives or strings proactively.","Pin/upgrade polars versions and check release notes for newly supported serializers."],"tags":["json-serialization","not-implemented","arrow","panic"],"backgroundTag":"method-not-implemented","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}