_json.py 473 B

123456789101112131415161718
  1. from __future__ import annotations
  2. import json as _json
  3. import typing as t
  4. class _CompactJSON:
  5. """Wrapper around json module that strips whitespace."""
  6. @staticmethod
  7. def loads(payload: str | bytes) -> t.Any:
  8. return _json.loads(payload)
  9. @staticmethod
  10. def dumps(obj: t.Any, **kwargs: t.Any) -> str:
  11. kwargs.setdefault("ensure_ascii", False)
  12. kwargs.setdefault("separators", (",", ":"))
  13. return _json.dumps(obj, **kwargs)