{"record":{"id":"640c961d3f0accbc","repo":"SeaQL/sea-orm","slug":"failed-to-get-json","errorCode":null,"errorMessage":"Failed to get json","messagePattern":"Failed to get json","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_mysql.rs","lineNumber":533,"sourceCode":"                        \"DECIMAL\" => Value::BigDecimal(\n                            row.try_get::<Option<bigdecimal::BigDecimal>, _>(c.ordinal())\n                                .expect(\"Failed to get decimal\")\n                                .map(Box::new),\n                        ),\n                        #[cfg(all(\n                            feature = \"with-rust_decimal\",\n                            not(feature = \"with-bigdecimal\")\n                        ))]\n                        \"DECIMAL\" => Value::Decimal(\n                            row.try_get::<Option<rust_decimal::Decimal>, _>(c.ordinal())\n                                .expect(\"Failed to get decimal\")\n                                .map(Box::new),\n                        ),\n\n                        #[cfg(feature = \"with-json\")]\n                        \"JSON\" => Value::Json(\n                            row.try_get::<Option<serde_json::Value>, _>(c.ordinal())\n                                .expect(\"Failed to get json\")\n                                .map(Box::new),\n                        ),\n\n                        _ => unreachable!(\"Unknown column type: {}\", c.type_info().name()),\n                    },\n                )\n            })\n            .collect(),\n    }\n}\n","sourceCodeStart":515,"sourceCodeEnd":544,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_mysql.rs#L515-L544","documentation":"A panic from `.expect(\"Failed to get json\")` in ProxyRow's MySQL conversion: the column type_info reports JSON, but `row.try_get::<Option<serde_json::Value>>` failed, so expect aborts instead of returning an error. This requires the with-json feature.","triggerScenarios":"Reading a MySQL JSON column where the raw value is not valid JSON (invalid JSON text stored via casts or older column types), or sqlx decodes it as String rather than serde_json::Value so the type lookup fails.","commonSituations":"Columns migrated from TEXT/LONGTEXT to JSON containing malformed data; reading JSON columns through drivers/versions that return them as strings; JSON columns containing values sqlx's serde_json decoder rejects.","solutions":["Validate the column contents: run SELECT and JSON_VALID(col) to find malformed rows and repair or NULL them.","Ensure the column is a real MySQL JSON type and your sqlx version decodes JSON natively; cast with CAST(col AS JSON) in the query if needed.","Align sea-orm/sqlx versions so JSON decoding is supported for your MySQL server version.","Change the expect to a mapped error so decode failures return DbErr instead of panicking."],"exampleFix":"// before\nrow.try_get::<Option<serde_json::Value>, _>(c.ordinal())\n    .expect(\"Failed to get json\")\n// after\nrow.try_get::<Option<serde_json::Value>, _>(c.ordinal())\n    .map_err(|e| DbErr::Custom(format!(\"json decode failed for {}: {e}\", c.name())))?","handlingStrategy":"validation","validationCode":"// Check stored JSON is valid before conversion\n// SELECT COUNT(*) FROM t WHERE JSON_VALID(col) = 0;  -- must be 0\nlet info = c.type_info().name();\nif info != \"JSON\" {\n    return Err(format!(\"unexpected column type {info} for json decoding\"));\n}","typeGuard":"fn is_json_column(c: &sqlx::mysql::MySqlColumn) -> bool {\n    c.type_info().name() == \"JSON\"\n}","tryCatchPattern":null,"preventionTips":["Validate all rows with MySQL's JSON_VALID after migrating TEXT columns to JSON","Use real JSON column types, not TEXT holding JSON strings","Enable the with-json feature consistently across crates","Keep sqlx/sea-orm versions aligned so JSON decoding works for your MySQL version","Cast suspicious columns with CAST(col AS JSON) at query time"],"tags":["mysql","json","decode","panic","sqlx"],"backgroundTag":"type-mismatch","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}