[docs]defload_any(self,source:Union[str,dict,TextIO,Path],target_class:type[Union[BaseModel,YAMLRoot]],*,base_dir:Optional[str]=None,metadata:Optional[FileInfo]=None,**_,)->Union[BaseModel,YAMLRoot,list[BaseModel],list[YAMLRoot]]:""" Load the JSON in source into the python target_class structure :param source: JSON data source. Can be a URL, a file name, a JSON string, a resolveable filepath or an existing graph :param target_class: LinkML class to load the JSON into :param base_dir: Base directory that can be used if file name or URL. This is copied into metadata if present :param metadata: source information. Used by some loaders to record where information came from :return: data instances of target_class """# see https://github.com/linkml/linkml/issues/2458, this works around a limitation in hbreaderifisinstance(source,Path):full_path=source.resolve()try:withfull_path.open("r",encoding="utf-8")asfile:new_source=json.load(file)source=new_sourceexceptFileNotFoundErrorase:raiseValueError(f"File not found: {source}")fromeexceptjson.JSONDecodeErrorase:raiseValueError(f"Invalid JSON in {source}: {e}")data_as_dict=self.load_as_dict(source,base_dir=base_dir,metadata=metadata)ifisinstance(data_as_dict,dict):typ=data_as_dict.pop("@type",None)iftypandtyp!=target_class.__name__:logger.warning(f"Warning: input type mismatch. Expected: {target_class.__name__}, Actual: {typ}")returnself._construct_target_class(data_as_dict,target_class)