Alternative helper method that does not use `argparse` at all, instead loading a json file and populating the dataclass types. Args: json_file (`str` or `os.PathLike`): File name of the json file to parse allow_extra_keys (`bool`, *op
(self, json_file: str | os.PathLike, allow_extra_keys: bool = False)
| 384 | return tuple(outputs) |
| 385 | |
| 386 | def parse_json_file(self, json_file: str | os.PathLike, allow_extra_keys: bool = False) -> tuple[DataClass, ...]: |
| 387 | """ |
| 388 | Alternative helper method that does not use `argparse` at all, instead loading a json file and populating the |
| 389 | dataclass types. |
| 390 | |
| 391 | Args: |
| 392 | json_file (`str` or `os.PathLike`): |
| 393 | File name of the json file to parse |
| 394 | allow_extra_keys (`bool`, *optional*, defaults to `False`): |
| 395 | Defaults to False. If False, will raise an exception if the json file contains keys that are not |
| 396 | parsed. |
| 397 | |
| 398 | Returns: |
| 399 | Tuple consisting of: |
| 400 | |
| 401 | - the dataclass instances in the same order as they were passed to the initializer. |
| 402 | """ |
| 403 | with open(Path(json_file), encoding="utf-8") as open_json_file: |
| 404 | data = json.loads(open_json_file.read()) |
| 405 | outputs = self.parse_dict(data, allow_extra_keys=allow_extra_keys) |
| 406 | return tuple(outputs) |
| 407 | |
| 408 | def parse_yaml_file(self, yaml_file: str | os.PathLike, allow_extra_keys: bool = False) -> tuple[DataClass, ...]: |
| 409 | """ |