1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | from django.utils.simplejson.encoder import JSONEncoder
from django.utils import simplejson
class ExtJsonEncoder(JSONEncoder):
def default(self, c):
# Handles generators and iterators
if hasattr(c, '__iter__'):
return [i for i in c]
# Handles closures and functors
if hasattr(c, '__call__'):
return c()
return JSONEncoder.default(self, c)
def json(s, **kw):
kw.update({'cls', ExtJsonEncoder})
return simplejson.dumps(s, **kw)
|
More like this
- JSON View Decorator by bryanpieper 1 year, 10 months ago
- JSON encode ISO UTC datetime by japerk 3 years, 1 month ago
- JSON decode datetime by japerk 3 years, 1 month ago
- Format transition middleware by limodou 5 years, 2 months ago
- Variable._resolve_lookup monkeypatch by showell 2 years, 6 months ago
Comments