Skip to content

Commit d1a7436

Browse files
asdil12dpgeorge
authored andcommitted
unix-ffi/json: Accept both str and bytes as arg for json.loads().
Same as micropython's internal json lib does. Fixes #985. Signed-off-by: Dominik Heidler <[email protected]>
1 parent f72f3f1 commit d1a7436

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

unix-ffi/json/json/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ def loads(
354354
object_pairs_hook=None,
355355
**kw
356356
):
357-
"""Deserialize ``s`` (a ``str`` instance containing a JSON
358-
document) to a Python object.
357+
"""Deserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance
358+
containing a JSON document) to a Python object.
359359
360360
``object_hook`` is an optional function that will be called with the
361361
result of any object literal decode (a ``dict``). The return value of
@@ -413,4 +413,6 @@ def loads(
413413
kw["parse_int"] = parse_int
414414
if parse_constant is not None:
415415
kw["parse_constant"] = parse_constant
416+
if isinstance(s, (bytes, bytearray)):
417+
s = s.decode('utf-8')
416418
return cls(**kw).decode(s)

0 commit comments

Comments
 (0)