How to use the ujson.JSONEncoder._olddefault function in ujson

To help you get started, we’ve selected a few ujson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github krateng / maloja / maloja / monkey.py View on Github external
# custom json encoding



def newdefault(self,object):
	return getattr(object.__class__,"__json__", self._olddefault)(object)


# just patch every encoder
try:
	from simplejson import JSONEncoder
	JSONEncoder._olddefault = JSONEncoder.default
	JSONEncoder.default = newdefault
except:
	pass

try:
	from json import JSONEncoder
	JSONEncoder._olddefault = JSONEncoder.default
	JSONEncoder.default = newdefault
except:
	pass

try:
	from ujson import JSONEncoder
	JSONEncoder._olddefault = JSONEncoder.default
	JSONEncoder.default = newdefault
except: