diff --git a/unix-ffi/json/json/__init__.py b/unix-ffi/json/json/__init__.py index 954618f33..5773f71fc 100644 --- a/unix-ffi/json/json/__init__.py +++ b/unix-ffi/json/json/__init__.py @@ -391,6 +391,8 @@ def loads( The ``encoding`` argument is ignored and deprecated. """ + if isinstance(s, (bytes, bytearray)): + s = s.decode('utf-8') if ( cls is None and object_hook is None @@ -413,6 +415,4 @@ def loads( kw["parse_int"] = parse_int if parse_constant is not None: kw["parse_constant"] = parse_constant - if isinstance(s, (bytes, bytearray)): - s = s.decode('utf-8') return cls(**kw).decode(s) diff --git a/unix-ffi/json/test_json.py b/unix-ffi/json/test_json.py index 7d7ba2104..163f558c8 100644 --- a/unix-ffi/json/test_json.py +++ b/unix-ffi/json/test_json.py @@ -11,3 +11,9 @@ # Doesn't work because JSON doesn't have tuples # assert inp == outp + +b = b'["foo", {"bar": ["baz", null, 1, 2]}]' +outp2 = json.loads(b) + +assert b.decode('utf-8') == s +assert outp == outp2