Transform a json object string into a BoxList object. If the incoming json is a dict, you must use Box.from_json. :param json_string: string to pass to `json.loads` :param filename: filename to open and pass to `json.load` :param encoding: File encoding
(
cls,
json_string: str | None = None,
filename: str | PathLike | None = None,
encoding: str = "utf-8",
errors: str = "strict",
multiline: bool = False,
**kwargs,
)
| 490 | |
| 491 | @classmethod |
| 492 | def from_json( |
| 493 | cls, |
| 494 | json_string: str | None = None, |
| 495 | filename: str | PathLike | None = None, |
| 496 | encoding: str = "utf-8", |
| 497 | errors: str = "strict", |
| 498 | multiline: bool = False, |
| 499 | **kwargs, |
| 500 | ): |
| 501 | """ |
| 502 | Transform a json object string into a BoxList object. If the incoming |
| 503 | json is a dict, you must use Box.from_json. |
| 504 | |
| 505 | :param json_string: string to pass to `json.loads` |
| 506 | :param filename: filename to open and pass to `json.load` |
| 507 | :param encoding: File encoding |
| 508 | :param errors: How to handle encoding errors |
| 509 | :param multiline: One object per line, in a string or file |
| 510 | :param kwargs: parameters to pass to `Box()` or `json.loads` |
| 511 | :return: BoxList object from json data |
| 512 | """ |
| 513 | box_args = {} |
| 514 | for arg in list(kwargs.keys()): |
| 515 | if arg in BOX_PARAMETERS: |
| 516 | box_args[arg] = kwargs.pop(arg) |
| 517 | |
| 518 | data = _from_json( |
| 519 | json_string, filename=filename, encoding=encoding, errors=errors, multiline=multiline, **kwargs |
| 520 | ) |
| 521 | |
| 522 | if not isinstance(data, list): |
| 523 | raise BoxError(f"json data not returned as a list, but rather a {type(data).__name__}") |
| 524 | return cls(data, **box_args) |
| 525 | |
| 526 | if yaml_available: |
| 527 |
nothing calls this directly
no test coverage detected