MisterAI's picture
download
raw
1.05 kB
"""JSON serialize to/from utf8 bytes
.. versionchanged:: 22.2
Remove optional imports of different JSON implementations.
Now that we require recent Python, unconditionally use the standard library.
Custom JSON libraries can be used via custom serialization functions.
"""
# Copyright (C) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.
from __future__ import annotations
import json
from typing import Any
# backward-compatibility, unused
jsonmod = json
def dumps(o: object, **kwargs: Any) -> bytes:
"""Serialize object to JSON bytes (utf-8).
Keyword arguments are passed along to :py:func:`json.dumps`.
"""
return json.dumps(o, **kwargs).encode("utf8")
def loads(s: bytes | str, **kwargs: Any) -> dict[str, Any] | list[Any] | str | float:
"""Load object from JSON bytes (utf-8).
Keyword arguments are passed along to :py:func:`json.loads`.
"""
if isinstance(s, bytes):
s = s.decode("utf8")
return json.loads(s, **kwargs)
__all__ = ['dumps', 'loads']

Xet Storage Details

Size:
1.05 kB
·
Xet hash:
9785ae4dd2e698fe8169bb396360da4cb59b325a5e41c6b209dccec3f05c8bf9

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.