Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d1a7436

Browse files
aylen384dpgeorge
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 <dheidler@suse.de>
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‎

Lines changed: 4 additions & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /