Skip to content

Commit

Permalink
add ability to parse dicts and lists
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry committed May 17, 2024
1 parent 12965c0 commit e834ecb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions xgi/readwrite/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ def write_json_collection(collection, dir, collection_name=None):
collection_data = defaultdict(dict)
if collection_name is not None:
collection_name += "_"

for i, H in enumerate(collection):
path = f"{dir}/{collection_name}{i}.json"
collection_data["path"][i] = path
write_json(H, path)
if isinstance(collection, list):
for i, H in enumerate(collection):
path = f"{dir}/{collection_name}{i}.json"
collection_data["path"][i] = path
write_json(H, path)
elif isinstance(collection, dict):
for name, H in collection.items():
path = f"{dir}/{collection_name}{name}.json"
collection_data["path"][name] = path
write_json(H, path)

collection_data["type"] = "collection"

Expand Down

0 comments on commit e834ecb

Please sign in to comment.