SeaQL/sea-orm · error
Failed to get json array
Error message
Failed to get json array
What it means
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.
Source
Thrown at src/driver/sqlx_postgres.rs:666
.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 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.
Example fix
// before
.expect("Failed to get json array")
// after
.map_err(|e| DbErr::TryIntoError { value_type: "json[]".into(), source: e.into() })? Defensive patterns
Strategy: validation
Validate before calling
let udt: (String,) = sqlx::query_as(
"SELECT udt_name FROM information_schema.columns WHERE table_name=$1 AND column_name=$2",
)
.bind("my_table").bind("tags").fetch_one(&pool).await?;
assert!(udt.0 == "_json" || udt.0 == "_jsonb", "not a json array: {}", udt.0); Type guard
fn is_json_array(udt_name: &str) -> bool { matches!(udt_name, "_json" | "_jsonb") } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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 uuid array
- Failed to get oid array
- Failed to get json
- Failed to get ip address array
- Failed to get mac address array
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/5c15f8502580ac63.
Report an issue: GitHub.