import json def json_encode(o): t = type(o) if t is list or t is tuple: return json.dumps([oo.__dict__ for oo in o]) else: return json.dumps(o.__dict__)