I have the Employee classs which has name age and the Addresses list, which contains the list of addresses for the employee.
My Code design are as follows
class Employee:
Name=''
Age =''
Addresses =[]
class Address:
State =''
District =''
City=''
adress1 =Address();
adress1.State='West bengal'
adress1.District ='Jalpaiguri'
adress1.City= 'Kolkata'
adress2 =Address()
adress2.State='West Bengal'
adress2.District ='Darjeeling'
adress2.City= 'Siliguri'
employee =Employee()
employee.name ='Gunjan'
employee.age =22
employee.Addresses.append(adress1)
employee.Addresses.append(adress2)
I want to convert the employee to json representation. I tried
json.dumps(employee.__dict__).
But this is giving me only the name and age property of Employee but not the list of addresses it contains.
It would be great help if someone would guide me to get the perfect json representation something like-
{"name":"Gunjan","Age":"22","Addresses" :[{"State":"West Bengal","City":"Siliguri","District":"Darjeeling"},{"State":"West Bengal","City":"Kolkata","District":"New Jalpaiguri"}]}
Thank you