_json.py 450 B

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