{"record":{"id":"5c15f8502580ac63","repo":"SeaQL/sea-orm","slug":"failed-to-get-json-array-5c15f8","errorCode":null,"errorMessage":"Failed to get json array","messagePattern":"Failed to get json array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_postgres.rs","lineNumber":666,"sourceCode":"                                            .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                        ),\n\n                        #[cfg(feature = \"with-ipnetwork\")]\n                        \"INET\" | \"CIDR\" => Value::IpNetwork(\n                            row.try_get::<Option<ipnetwork::IpNetwork>, _>(c.ordinal())\n                                .expect(\"Failed to get ip address\"),\n                        ),\n                        #[cfg(feature = \"with-ipnetwork\")]\n                        \"INET[]\" | \"CIDR[]\" => Value::Array(\n                            sea_query::ArrayType::IpNetwork,\n                            row.try_get::<Option<Vec<ipnetwork::IpNetwork>>, _>(c.ordinal())","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L648-L684","documentation":"For JSON[]/JSONB[] columns, ProxyRow calls row.try_get::<Option<Vec<serde_json::Value>>, _> and .expect(\"Failed to get json array\") panics on sqlx decode failure. The value claimed to be a JSON array could not be decoded as Vec<serde_json::Value> — usually it is not actually an array of json on the wire, or an element cannot be represented in serde_json.","triggerScenarios":"A query selecting a column whose type name is \"JSON[]\"/\"JSONB[]\" but whose value is a scalar json, a 2-D array, or a domain-over-array; requires the json-array or postgres-array feature for the arm to compile.","commonSituations":"Schema drift where a text[] holds JSON strings; reading from a view or FDW that reports the wrong array element type; feature flags changed (json-array removed) so the column now falls into a different decode path.","solutions":["Confirm the column is truly jsonb[] / json[] (udt_name like _jsonb) and normalize with ALTER ... TYPE jsonb[] USING col::jsonb[].","Cast in SQL: SELECT my_col::jsonb[] AS my_col.","Enable both with-json and the relevant array feature (postgres-array or json-array) in sea-orm features.","Replace .expect with mapped DbErr to get actionable diagnostics."],"exampleFix":"// before\n.expect(\"Failed to get json array\")\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(\"tags\").fetch_one(&pool).await?;\nassert!(udt.0 == \"_json\" || udt.0 == \"_jsonb\", \"not a json array: {}\", udt.0);","typeGuard":"fn is_json_array(udt_name: &str) -> bool { matches!(udt_name, \"_json\" | \"_jsonb\") }","tryCatchPattern":null,"preventionTips":["Use genuine jsonb[] columns instead of text[] holding JSON strings","Enable the json-array or postgres-array feature explicitly","Avoid 2-D arrays where the decoder expects 1-D","Cast to ::jsonb[] in SQL for views/FDWs with fuzzy types"],"tags":["rust","sqlx","postgres","json","array"],"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"}