diff --git a/crates/polars-io/src/json/mod.rs b/crates/polars-io/src/json/mod.rs index f58a9010ac25..93e40993206b 100644 --- a/crates/polars-io/src/json/mod.rs +++ b/crates/polars-io/src/json/mod.rs @@ -281,7 +281,14 @@ where } else { simd_json::to_borrowed_value(owned).map_err(to_compute_err)? }; - + match &json_value { + BorrowedValue::Array(array) => { + if array.is_empty() { + return Ok(DataFrame::empty()); + } + }, + _ => {}, + } // struct type let dtype = if let Some(mut schema) = self.schema { if let Some(overwrite) = self.schema_overwrite { diff --git a/py-polars/tests/unit/io/test_json.py b/py-polars/tests/unit/io/test_json.py index 4e24cf3b08cd..bc32bc93f814 100644 --- a/py-polars/tests/unit/io/test_json.py +++ b/py-polars/tests/unit/io/test_json.py @@ -420,3 +420,13 @@ def test_compressed_json() -> None: uncompressed = io.BytesIO(json_bytes) out = pl.read_json(uncompressed) assert_frame_equal(out, expected) + + +def test_empty_list_json() -> None: + df = pl.read_json(io.StringIO("[]")) + assert df.shape == (0, 0) + assert isinstance(df, pl.DataFrame) + + df = pl.read_json(b"[]") + assert df.shape == (0, 0) + assert isinstance(df, pl.DataFrame)