I am using json.dumps to display my object in json format.
My object
class Listing(object):
name = ""
introduction = ""
products = []
class MenuItem(object):
name = ""
new_listing = Listing()
new_listing.introduction = "this is my intro"
menuitem1 = MenuItem()
menuitem1.name = "product 1"
new_listing.products.append(menuitem1)
jsonstr = json.dumps(new_listing.__dict__, indent=4, separators=(". ", " = "))
print(jsonstr)
Output
{
"introduction" = "this is my intro"
}
May I ask how do I get listing.products to appear in json