{"record":{"id":"ef993d9ea5b70ab4","repo":"SeaQL/sea-orm","slug":"failed-to-get-json-ef993d","errorCode":null,"errorMessage":"Failed to get json","messagePattern":"Failed to get json","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_postgres.rs","lineNumber":656,"sourceCode":"                        }\n                        #[cfg(feature = \"postgres-array\")]\n                        \"OID[]\" => Value::Array(\n                            sea_query::ArrayType::BigInt,\n                            row.try_get::<Option<Vec<i64>>, _>(c.ordinal())\n                                .expect(\"Failed to get oid array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::BigInt(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        #[cfg(feature = \"with-json\")]\n                        \"JSON\" | \"JSONB\" => Value::Json(\n                            row.try_get::<Option<serde_json::Value>, _>(c.ordinal())\n                                .expect(\"Failed to get json\")\n                                .map(Box::new),\n                        ),\n                        #[cfg(all(\n                            feature = \"with-json\",\n                            any(feature = \"json-array\", feature = \"postgres-array\")\n                        ))]\n                        \"JSON[]\" | \"JSONB[]\" => Value::Array(\n                            sea_query::ArrayType::Json,\n                            row.try_get::<Option<Vec<serde_json::Value>>, _>(c.ordinal())\n                                .expect(\"Failed to get json array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::Json(Some(Box::new(val))))\n                                            .collect(),\n                                    )\n                                }),\n                        ),","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L638-L674","documentation":"ProxyRow decodes Postgres JSON/JSONB columns into serde_json::Value and .expect(\"Failed to get json\") panics on sqlx decode failure. Since the target is Option<serde_json::Value>, NULL is handled; the panic means the value's wire type isn't json/jsonb as sqlx sees it, or the value contains something serde_json cannot represent (e.g. NaN/Infinity produced by non-standard serializers).","triggerScenarios":"Selecting a column named \"JSON\"/\"JSONB\" by type when the server actually returns a different wire format (e.g. a domain over jsonb in an older Postgres wire type, or a text column that the driver misclassifies), or with the with-json feature enabled while the value exceeds sqlx's decoding limits.","commonSituations":"Columns created via an ORM migration that ended up as text instead of jsonb; reading a view whose output type differs from the base table; Postgres extensions returning json-compatible types under a different OID.","solutions":["Check the column's real type (udt_name should be json or _/jsonb) and fix the schema with ALTER TABLE ... ALTER COLUMN ... TYPE jsonb USING col::jsonb.","Cast in the query: SELECT my_col::jsonb AS my_col.","Ensure the with-json feature (and compatible serde_json version) is enabled on both sea-orm and the sqlx dependency.","In driver code, replace .expect with error propagation (DbErr::TryIntoError) to surface which ordinal failed."],"exampleFix":"// before\n.expect(\"Failed to get json\")\n// after\n.map_err(|e| DbErr::TryIntoError { value_type: \"json\".into(), source: e.into() })?","handlingStrategy":"validation","validationCode":"let udt: (String,) = sqlx::query_as(\n    \"SELECT udt_name FROM information_schema.columns WHERE table_name=$1 AND column_name=$2\",\n)\n.bind(\"my_table\").bind(\"payload\").fetch_one(&pool).await?;\nassert!(matches!(udt.0.as_str(), \"json\" | \"jsonb\"), \"not a json column: {}\", udt.0);","typeGuard":"fn is_json_type(udt_name: &str) -> bool { matches!(udt_name, \"json\" | \"jsonb\") }","tryCatchPattern":null,"preventionTips":["Store JSON in real jsonb columns, never text pretending to be json","Keep the with-json feature and a serde_json version matching sqlx","Validate data written by other clients is valid JSON (jsonb enforces this)","Avoid domains over json/jsonb for proxy-read tables"],"tags":["rust","sqlx","postgres","json","panic"],"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"}