def loads(s: str, **kwargs) -> JsonObj: """ Convert a json_str into a JsonObj :param s: a str instance containing a JSON document :param kwargs: arguments see: json.load for details :return: JsonObj representing the json string """ if isinstance(s, (bytes, bytearray)): s = s.decode(json.detect_encoding(s), 'surrogatepass') return json.loads(s, object_hook=lambda pairs: JsonObj(**pairs), **kwargs)
def test_detect_encoding(self, value, encoding): data = json.dumps(value).encode(encoding) assert json.detect_encoding(data) == encoding assert json.loads(data) == value
def test_detect_encoding(self, value, encoding): data = json.dumps(value).encode(encoding) assert json.detect_encoding(data) == encoding assert json.loads(data) == value