Skip to content

Commit

Permalink
[feature] support reading a dict representing a json doc (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
menathan authored Feb 27, 2025
1 parent 7cd04bb commit d6ef80d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/koheesio/spark/readers/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
5 changes: 4 additions & 1 deletion tests/spark/readers/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d6ef80d

Please sign in to comment.