_json.py 431 B

123456789101112131415161718
  1. try:
  2. import simplejson as json
  3. except ImportError:
  4. import json
  5. class _CompactJSON(object):
  6. """Wrapper around json module that strips whitespace."""
  7. @staticmethod
  8. def loads(payload):
  9. return json.loads(payload)
  10. @staticmethod
  11. def dumps(obj, **kwargs):
  12. kwargs.setdefault("ensure_ascii", False)
  13. kwargs.setdefault("separators", (",", ":"))
  14. return json.dumps(obj, **kwargs)