diff --git a/dcicutils/structured_data.py b/dcicutils/structured_data.py index e80caf637..6d489ea17 100644 --- a/dcicutils/structured_data.py +++ b/dcicutils/structured_data.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 421985fb9..97f5f588e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT"