python-kasa/kasa/json.py
Steven B e233e377ad
Generate AES KeyPair lazily (#687)
* Generate AES KeyPair lazily

* Fix coverage

* Update post-review

* Fix pragma

* Make json dumps consistent between python and orjson

* Add comment

* Add comments re json parameter in HttpClient
2024-01-23 15:29:27 +00:00

20 lines
415 B
Python
Executable File

"""JSON abstraction."""
try:
import orjson
def dumps(obj, *, default=None):
"""Dump JSON."""
return orjson.dumps(obj).decode()
loads = orjson.loads
except ImportError:
import json
def dumps(obj, *, default=None):
"""Dump JSON."""
# Separators specified for consistency with orjson
return json.dumps(obj, separators=(",", ":"))
loads = json.loads