Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/zmq/utils/jsonapi.py: 60%
10 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""JSON serialize to/from utf8 bytes
3.. versionchanged:: 22.2
4 Remove optional imports of different JSON implementations.
5 Now that we require recent Python, unconditionally use the standard library.
6 Custom JSON libraries can be used via custom serialization functions.
7"""
9# Copyright (C) PyZMQ Developers
10# Distributed under the terms of the Modified BSD License.
12import json
13from typing import Any, Dict, List, Union
15# backward-compatibility, unused
16jsonmod = json
19def dumps(o: Any, **kwargs) -> bytes:
20 """Serialize object to JSON bytes (utf-8).
22 Keyword arguments are passed along to :py:func:`json.dumps`.
23 """
24 return json.dumps(o, **kwargs).encode("utf8")
27def loads(s: Union[bytes, str], **kwargs) -> Union[Dict, List, str, int, float]:
28 """Load object from JSON bytes (utf-8).
30 Keyword arguments are passed along to :py:func:`json.loads`.
31 """
32 if isinstance(s, bytes):
33 s = s.decode("utf8")
34 return json.loads(s, **kwargs)
37__all__ = ['dumps', 'loads']