@
cloudzhou import json
import cgi
import functools
def encoder(o, _encoder=json.encoder.encode_basestring):
.... if isinstance(o, basestring):
........o = cgi.escape(o)
....return _encoder(o)
json.encoder.encode_basestring = encoder
json.encoder.encode_basestring_ascii = functools.partial(encoder, _encoder=json.encoder.encode_basestring_ascii)
print json.dumps({'<xss>': '<script>alert(1)</script>'})
{"<xss>": "<script>alert(1)</script>"}