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

Method from_json

box/box.py:1368–1396  ·  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

1366
1367 @classmethod
1368 def from_json(
1369 cls,
1370 json_string: str | None = None,
1371 filename: str | PathLike | None = None,
1372 encoding: str = "utf-8",
1373 errors: str = "strict",
1374 **kwargs,
1375 ) -> Box:
1376 """
1377 Transform a json object string into a Box object. If the incoming
1378 json is a list, you must use BoxList.from_json.
1379
1380 :param json_string: string to pass to `json.loads`
1381 :param filename: filename to open and pass to `json.load`
1382 :param encoding: File encoding
1383 :param errors: How to handle encoding errors
1384 :param kwargs: parameters to pass to `Box()` or `json.loads`
1385 :return: Box object from json data
1386 """
1387 box_args = {}
1388 for arg in kwargs.copy():
1389 if arg in BOX_PARAMETERS:
1390 box_args[arg] = kwargs.pop(arg)
1391
1392 data = _from_json(json_string, filename=filename, encoding=encoding, errors=errors, **kwargs)
1393
1394 if not isinstance(data, dict):
1395 raise BoxError(f"json data not returned as a dictionary, but rather a {type(data).__name__}")
1396 return cls(data, **box_args)
1397
1398 if yaml_available:
1399

Calls 4

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