class MyEncoder(JSONEncoder): # this is the only worked approach def iterencode(self, obj, *args, **kwargs): if isinstance(obj, tuple) and hasattr(ob