Re: Shopify Python API : How to serialize products list to JSON?

Shopify Python API : How to serialize products list to JSON?

sagar-wal
Visitor
1 0 0

I want to fetch Products list and return as JSON using the Shopify Python API.

I tried the .to_json() function

products=shopify.Product.find().to_json()

Got the error

'PaginatedCollection' object has no attribute 'to_json'

I tried doing

products=shopify.Product.find() 
js=json.dumps(products)

Error:

Object of type Product is not JSON serializable

 

How can I serialize the Products response to JSON ?

Replies 2 (2)

skulogi
Excursionist
11 2 4

You can use jsonpickle for this.

 

import jsonpickle

products = shopify.Product.find()
products_page_json  =jsonpickle.encode(products)

 

Building SKULogi – AI based Demand Forecasting and Inventory Planning


If interested check out this blog for more details.

jam_chan
Shopify Partner
920 23 187
shopify.Product.find()

return a list of products. to_json() is a method of Product object. Of course, it's throwing errors

Seriously you should test with shell 

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview