SeaQL/sea-orm · error
Failed to get json
Error message
Failed to get json
What it means
This panic comes from `.expect("Failed to get json")` in the sqlx MySQL driver's ProxyRow conversion when a JSON-typed column is decoded into `Option<serde_json::Value>` (behind the `with-json` feature). If sqlx fails to decode the value as JSON -- such as malformed JSON text stored in the column, or a runtime type mismatch -- the expect panics. It indicates the stored value could not be materialized as a serde_json::Value.
Source
Thrown at src/driver/sqlx_mysql.rs:541
"DECIMAL" => Value::BigDecimal(
row.try_get::<Option<bigdecimal::BigDecimal>, _>(c.ordinal())
.expect("Failed to get decimal")
.map(Box::new),
),
#[cfg(all(
feature = "with-rust_decimal",
not(feature = "with-bigdecimal")
))]
"DECIMAL" => Value::Decimal(
row.try_get::<Option<rust_decimal::Decimal>, _>(c.ordinal())
.expect("Failed to get decimal")
.map(Box::new),
),
#[cfg(feature = "with-json")]
"JSON" => Value::Json(
row.try_get::<Option<serde_json::Value>, _>(c.ordinal())
.expect("Failed to get json")
.map(Box::new),
),
_ => unreachable!("Unknown column type: {}", c.type_info().name()),
},
)
})
.collect(),
}
}
View on GitHub (pinned to e29bcd1b41)
Solutions
- Validate the stored data: `SELECT col FROM t WHERE JSON_VALID(col) = 0` to find invalid rows, then repair or migrate them.
- Cast in SQL when the column is not a true JSON type: `CAST(col AS JSON)` or select as TEXT and parse in application code.
- Ensure the entity column type is Json (with `with-json` enabled) and regenerate entities to match the schema.
- Align serde_json and sqlx versions in Cargo.lock if a recent upgrade introduced the failure.
- For mixed legacy data, clean the column with `UPDATE t SET col = JSON_VALID-based fixes` or move invalid rows to a TEXT column.
Example fix
// before
"SELECT meta FROM events" // meta is LONGTEXT with possibly invalid JSON
// after
"SELECT CAST(meta AS JSON) AS meta FROM events WHERE JSON_VALID(meta)"
// and clean invalid rows first:
"UPDATE events SET meta = '{}' WHERE JSON_VALID(meta) = 0" Defensive patterns
Strategy: validation
Validate before calling
// Find rows with invalid JSON before querying:
let bad = db.query_all(Statement::from_string(
DatabaseBackend::MySql,
"SELECT id FROM events WHERE meta IS NOT NULL AND JSON_VALID(meta) = 0",
)).await?;
assert!(bad.is_empty(), "invalid JSON stored in events.meta"); Prevention
- Use real MySQL JSON column types so the DB enforces validity on insert.
- Run JSON_VALID checks/migrations on legacy TEXT columns holding JSON.
- Enable with-json and declare entity columns as Json to match.
- Guard writes through serde serialization rather than string concatenation.
When it happens
Trigger: Fetching a MySQL JSON (or TEXT holding JSON) column while `with-json` is enabled and `row.try_get::<Option<serde_json::Value>, _>(c.ordinal())` errors -- typically because the column contains invalid JSON or the sqlx value type is not JSON.
Common situations: Legacy columns typed TEXT/LONGTEXT containing hand-written or truncated JSON; MySQL 5.7/8 JSON columns inserted via non-validating paths; enabling `with-json` after previously storing plain strings; raw SQL proxy queries over JSON columns with sqlx version drift.
Related errors
- Failed to get json
- Not MySQL Connection
- Not MySQL Connection
- Failed to get boolean
- Failed to get unsigned tiny integer
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/0626b05f60af030e.
Report an issue: GitHub.