SeaQL/sea-orm · error
Failed to get json array
Error message
Failed to get json array
What it means
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.
Source
Thrown at sea-orm-sync/src/driver/sqlx_postgres.rs:653
.collect(),
)
}),
),
#[cfg(feature = "with-json")]
"JSON" | "JSONB" => Value::Json(
row.try_get::<Option<serde_json::Value>, _>(c.ordinal())
.expect("Failed to get json")
.map(Box::new),
),
#[cfg(all(
feature = "with-json",
any(feature = "json-array", feature = "postgres-array")
))]
"JSON[]" | "JSONB[]" => Value::Array(
sea_query::ArrayType::Json,
row.try_get::<Option<Vec<serde_json::Value>>, _>(c.ordinal())
.expect("Failed to get json array")
.map(|vals| {
Box::new(
vals.into_iter()
.map(|val| Value::Json(Some(Box::new(val))))
.collect(),
)
}),
),
#[cfg(feature = "with-ipnetwork")]
"INET" | "CIDR" => Value::IpNetwork(
row.try_get::<Option<ipnetwork::IpNetwork>, _>(c.ordinal())
.expect("Failed to get ip address"),
),
#[cfg(feature = "with-ipnetwork")]
"INET[]" | "CIDR[]" => Value::Array(
sea_query::ArrayType::IpNetwork,
row.try_get::<Option<Vec<ipnetwork::IpNetwork>>, _>(c.ordinal())View on GitHub (pinned to e29bcd1b41)
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.
Example fix
// before CREATE TABLE t (docs text[]); // after ALTER TABLE t ALTER COLUMN docs TYPE jsonb[] USING docs::jsonb[];
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the column is a true json/jsonb array, not text[]:
let t = db.query_one(Statement::from_string(
DatabaseBackend::Postgres,
"SELECT format_type(a.atttypid, a.atttypmod) FROM pg_attribute a WHERE a.attrelid = 't'::regclass AND a.attname = 'docs'",
)).await?;
// expect "jsonb[]" Try / catch
// Fall back to text decoding and parse manually if the schema stores JSON in text[]:
let rows = db.query_all(Statement::from_string(
DatabaseBackend::Postgres,
"SELECT docs::text[] FROM t",
)).await?;
let docs: Vec<serde_json::Value> = rows[0].try_get::<Vec<String>, _>(0)?
.into_iter()
.map(|s| serde_json::from_str(&s))
.collect::<Result<_, _>>()?; Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Failed to get json
- Failed to get ip address array
- Failed to get mac address array
- Failed to get numeric array
- Failed to get oid
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/139d0132a685d0d4.
Report an issue: GitHub.