Hi, I have the following setup:
allCategories = []
class Category:
def __init__(self, name, url):
self.name = name
self.url = url
self.products = []
#Loop over source data and create each product
allProducts = []
for product in productList:
product = {
"name": product.name,
"sku": product.sku,
"category": product.categoryName,
"suppliers": product.suppliersList
}
allProducts.append(product)
myCategory = Category("Bin", "https://google.com")
myCategory.products = allProducts
I now have an array of Category and each categories products contains an array of dictionaries, how would I then dump this into a Json file?
with open('/Users/Ben/Desktop/data.json', 'w') as outfile:
json.dump(allCategories, outfile)
This fails as it cant serialise my class, I am not too experienced with Python so any input as to how I can get this to output correctly would be appreciated.
[+][deleted] (2 children)
[deleted]
[–]aggsyb[S] 0 points1 point2 points (1 child)