Issue 23473: Allow namedtuple to be JSON encoded as dict (original) (raw)
From memory, something along the lines of
from json import JSONEncoder
class ExtendedJSONEncoder(JSONEncoder):
def _iterencode(self, o, markers=None):
if isinstance(o, tuple) and hasattr(obj, '_fields'):
gen = self._iterencode_dict(o.__dict__, markers)
else:
gen = JSONEncoder._iterencode(self, o, markers)
for chunk in gen:
yield chunk