Skip to content

Commit

Permalink
fix: Raise on data mismatch in str.json_decode (#19347)
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion authored Oct 22, 2024
1 parent 11bd08e commit c6b2329
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 86 deletions.
8 changes: 7 additions & 1 deletion crates/polars-io/src/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ where
}
}

let allow_extra_fields_in_struct = self.schema.is_some();

// struct type
let dtype = if let Some(mut schema) = self.schema {
if let Some(overwrite) = self.schema_overwrite {
Expand Down Expand Up @@ -338,7 +340,11 @@ where
dtype
};

let arr = polars_json::json::deserialize(&json_value, dtype)?;
let arr = polars_json::json::deserialize(
&json_value,
dtype,
allow_extra_fields_in_struct,
)?;
let arr = arr.as_any().downcast_ref::<StructArray>().ok_or_else(
|| polars_err!(ComputeError: "can only deserialize json objects"),
)?;
Expand Down
Loading

0 comments on commit c6b2329

Please sign in to comment.