{"record":{"id":"0626b05f60af030e","repo":"SeaQL/sea-orm","slug":"failed-to-get-json-0626b0","errorCode":null,"errorMessage":"Failed to get json","messagePattern":"Failed to get json","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_mysql.rs","lineNumber":541,"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":523,"sourceCodeEnd":552,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_mysql.rs#L523-L552","documentation":"This panic comes from `.expect(\"Failed to get json\")` in the sqlx MySQL driver's ProxyRow conversion when a JSON-typed column is decoded into `Option<serde_json::Value>` (behind the `with-json` feature). If sqlx fails to decode the value as JSON -- such as malformed JSON text stored in the column, or a runtime type mismatch -- the expect panics. It indicates the stored value could not be materialized as a serde_json::Value.","triggerScenarios":"Fetching a MySQL JSON (or TEXT holding JSON) column while `with-json` is enabled and `row.try_get::<Option<serde_json::Value>, _>(c.ordinal())` errors -- typically because the column contains invalid JSON or the sqlx value type is not JSON.","commonSituations":"Legacy columns typed TEXT/LONGTEXT containing hand-written or truncated JSON; MySQL 5.7/8 JSON columns inserted via non-validating paths; enabling `with-json` after previously storing plain strings; raw SQL proxy queries over JSON columns with sqlx version drift.","solutions":["Validate the stored data: `SELECT col FROM t WHERE JSON_VALID(col) = 0` to find invalid rows, then repair or migrate them.","Cast in SQL when the column is not a true JSON type: `CAST(col AS JSON)` or select as TEXT and parse in application code.","Ensure the entity column type is Json (with `with-json` enabled) and regenerate entities to match the schema.","Align serde_json and sqlx versions in Cargo.lock if a recent upgrade introduced the failure.","For mixed legacy data, clean the column with `UPDATE t SET col = JSON_VALID-based fixes` or move invalid rows to a TEXT column."],"exampleFix":"// before\n\"SELECT meta FROM events\"  // meta is LONGTEXT with possibly invalid JSON\n\n// after\n\"SELECT CAST(meta AS JSON) AS meta FROM events WHERE JSON_VALID(meta)\"\n// and clean invalid rows first:\n\"UPDATE events SET meta = '{}' WHERE JSON_VALID(meta) = 0\"","handlingStrategy":"validation","validationCode":"// Find rows with invalid JSON before querying:\nlet bad = db.query_all(Statement::from_string(\n    DatabaseBackend::MySql,\n    \"SELECT id FROM events WHERE meta IS NOT NULL AND JSON_VALID(meta) = 0\",\n)).await?;\nassert!(bad.is_empty(), \"invalid JSON stored in events.meta\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use real MySQL JSON column types so the DB enforces validity on insert.","Run JSON_VALID checks/migrations on legacy TEXT columns holding JSON.","Enable with-json and declare entity columns as Json to match.","Guard writes through serde serialization rather than string concatenation."],"tags":["mysql","sqlx","json","panic"],"backgroundTag":"json-decode-failed","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}