Exemple #1
0
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)
Exemple #2
0
 def test_detect_encoding(self, value, encoding):
     data = json.dumps(value).encode(encoding)
     assert json.detect_encoding(data) == encoding
     assert json.loads(data) == value
Exemple #3
0
 def test_detect_encoding(self, value, encoding):
     data = json.dumps(value).encode(encoding)
     assert json.detect_encoding(data) == encoding
     assert json.loads(data) == value