Skip to content

Commit

Permalink
feat: read_json_files from a nested directory
Browse files Browse the repository at this point in the history
  • Loading branch information
OmaymaMahjoub committed Jan 22, 2024
1 parent be9e513 commit 7924983
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions marl_eval/utils/merge_json_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ def _read_json_files(directory: str) -> list:
"""Reads all JSON files in a directory and returns a list of JSON objects."""
json_data = []

for filename in os.listdir(directory):
if filename.endswith(".json"):
file_path = os.path.join(directory, filename)
with open(file_path) as file:
json_data.append(json.load(file))
for root, dirs, files in os.walk(directory):
for filename in files:
if filename.endswith(".json"):
file_path = os.path.join(root, filename)
with open(file_path) as file:
json_data.append(json.load(file))

return json_data


Expand Down

0 comments on commit 7924983

Please sign in to comment.