MCPcopy Create free account
hub / github.com/cdgriffith/Box / from_json

Method from_json

box/box.py:1351–1379  ·  view source on GitHub ↗

Transform a json object string into a Box object. If the incoming json is a list, you must use BoxList.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",
        **kwargs,
    )

Source from the content-addressed store, hash-verified

1349
1350 @classmethod
1351 def from_json(
1352 cls,
1353 json_string: str | None = None,
1354 filename: str | PathLike | None = None,
1355 encoding: str = "utf-8",
1356 errors: str = "strict",
1357 **kwargs,
1358 ) -> Box:
1359 """
1360 Transform a json object string into a Box object. If the incoming
1361 json is a list, you must use BoxList.from_json.
1362
1363 :param json_string: string to pass to `json.loads`
1364 :param filename: filename to open and pass to `json.load`
1365 :param encoding: File encoding
1366 :param errors: How to handle encoding errors
1367 :param kwargs: parameters to pass to `Box()` or `json.loads`
1368 :return: Box object from json data
1369 """
1370 box_args = {}
1371 for arg in kwargs.copy():
1372 if arg in BOX_PARAMETERS:
1373 box_args[arg] = kwargs.pop(arg)
1374
1375 data = _from_json(json_string, filename=filename, encoding=encoding, errors=errors, **kwargs)
1376
1377 if not isinstance(data, dict):
1378 raise BoxError(f"json data not returned as a dictionary, but rather a {type(data).__name__}")
1379 return cls(data, **box_args)
1380
1381 if yaml_available:
1382

Calls 4

_from_jsonFunction · 0.90
BoxErrorClass · 0.90
copyMethod · 0.80
popMethod · 0.45