From d6ef80dcea5cdac9fe0cc7e5e07a022a26e5dddd Mon Sep 17 00:00:00 2001 From: Nathan Melis Date: Thu, 27 Feb 2025 11:26:37 +0100 Subject: [PATCH] [feature] support reading a dict representing a json doc (#172) --- src/koheesio/spark/readers/memory.py | 2 ++ tests/spark/readers/test_memory.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/koheesio/spark/readers/memory.py b/src/koheesio/spark/readers/memory.py index a90e09ee..e069e7f7 100644 --- a/src/koheesio/spark/readers/memory.py +++ b/src/koheesio/spark/readers/memory.py @@ -95,6 +95,8 @@ def _json(self) -> DataFrame: elif isinstance(self.data, list): if all(isinstance(x, str) for x in self.data): json_data = [json.loads(x) for x in self.data] + else: + json_data = self.data else: json_data = [self.data] diff --git a/tests/spark/readers/test_memory.py b/tests/spark/readers/test_memory.py index 19c5b5c2..e43eafee 100644 --- a/tests/spark/readers/test_memory.py +++ b/tests/spark/readers/test_memory.py @@ -27,7 +27,10 @@ class TestInMemoryDataReader: ), pytest.param( ['{"id": 1, "string": "hello"}', '{"id": 2, "string": "world"}'], DataFormat.JSON, {}, "id < 3" - ) + ), + pytest.param( + [{"id": 1, "string": "hello"}, {"id": 2, "string": "world"}], DataFormat.JSON, {}, "id < 3" + ), ], ) # fmt: on