Skip to content

Commit

Permalink
better handle json files (unusual case) in structured_data
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed May 23, 2024
1 parent dbea701 commit 590efcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion dcicutils/structured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,18 @@ def get_counts() -> Tuple[int, int]:

def _load_json_file(self, file: str) -> None:
with open(file) as f:
self._add(Schema.type_name(file), json.load(f))
file_json = json.load(f)
schema_inferred_from_file_name = Schema.type_name(file)
if self._portal.get_schema(schema_inferred_from_file_name) is not None:
# If the JSON file name looks like a schema name then assume it
# contains an object or an array of object of that schema type.
self._add(Schema.type_name(file), file_json)
elif isinstance(file_json, dict):
# Otherwise if the JSON file name does not look like a schema name then
# assume it a dictionary where each property is the name of a schema, and
# which (each property) contains a list of object of that schema type.
for schema_name in file_json:
self._add(schema_name, file_json[schema_name])

def _load_reader(self, reader: RowReader, type_name: str) -> None:
schema = None
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.8.4.1b36" # TODO: To become 8.8.5
version = "8.8.4.1b37" # TODO: To become 8.8.5
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
license = "MIT"
Expand Down

0 comments on commit 590efcf

Please sign in to comment.