I have a class called Employee and there is list which contains instance of Employee. I tried the below approach:
class Employee:
empId
empName
def __init__(self, empId, empName):
self.empId = empId
self.empName = empName
class Test:
def convertJson(self):
employees=[]
emp1 = Employee(101,'John')
employees.append(emp1)
emp2 = Employee(102,'Smith')
employees.append(emp2)
employeeList = json.dumps(employees.__dict__) # Need to convert employees into json
It throws exception, list has no attribute 'dict