{"record":{"id":"139d0132a685d0d4","repo":"SeaQL/sea-orm","slug":"failed-to-get-json-array","errorCode":null,"errorMessage":"Failed to get json array","messagePattern":"Failed to get json array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":653,"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":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L635-L671","documentation":"This panic is raised when sea-orm cannot decode a JSON[]/JSONB[] array column into Option<Vec<serde_json::Value>> (gated on `with-json` plus `json-array` or `postgres-array`). try_get fails when the wire type is not a recognized json array, or the compiled sqlx build cannot decode arrays of json. The `.expect` makes the failure a hard panic during row conversion.","triggerScenarios":"Selecting a `json[]` or `jsonb[]` column with the array feature flags enabled but sqlx built without the corresponding array support; the column actually contains `text[]` holding JSON strings rather than a true jsonb[]; type OID for the array not recognized by the driver.","commonSituations":"Storing JSON documents in text[] instead of jsonb[] and expecting typed decoding; feature-flag mismatch (`json-array` on sea-orm but not propagated to sqlx); migrating data where the column type changed from text[] to jsonb[] without updating the entity.","solutions":["Confirm the true column type (`SELECT pg_typeof(col)`); if it is text[], change the schema to jsonb[] or decode as strings.","Enable `json-array` (or `postgres-array`) and `with-json` on the sea-orm dependency in every crate that compiles it.","Cast in SQL when types differ: `SELECT col::jsonb[] FROM t`.","Keep one sqlx version across the workspace (`cargo tree -d`) so array decoders match."],"exampleFix":"// before\nCREATE TABLE t (docs text[]);\n\n// after\nALTER TABLE t ALTER COLUMN docs TYPE jsonb[] USING docs::jsonb[];","handlingStrategy":"validation","validationCode":"// Ensure the column is a true json/jsonb array, not text[]:\nlet t = db.query_one(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT format_type(a.atttypid, a.atttypmod) FROM pg_attribute a WHERE a.attrelid = 't'::regclass AND a.attname = 'docs'\",\n)).await?;\n// expect \"jsonb[]\"","typeGuard":null,"tryCatchPattern":"// Fall back to text decoding and parse manually if the schema stores JSON in text[]:\nlet rows = db.query_all(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT docs::text[] FROM t\",\n)).await?;\nlet docs: Vec<serde_json::Value> = rows[0].try_get::<Vec<String>, _>(0)?\n    .into_iter()\n    .map(|s| serde_json::from_str(&s))\n    .collect::<Result<_, _>>()?;","preventionTips":["Store JSON arrays as jsonb[] (or jsonb with array semantics), not text[].","Enable with-json plus json-array/postgres-array together on sea-orm.","Keep one sqlx version across the workspace.","Check `pg_typeof(col)` whenever entity type and DB type might have drifted."],"tags":["postgres","json","type-decoding","panic","array","sea-orm"],"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"}