Python decoding objects back to json

Highlighted
Shopify Partner
2 0 1

Is there a way to keep the resources I pull from the API in JSON?  Trying to decode a shop object back into JSON via json.dumps(shop.__dict__) throws a 'shop(10768556) is not JSON serializable' error.

0 Likes
Highlighted
Shopify Partner
2 0 1

Nevermind, I just found to_dict(self): in pyactiveresource.

1 Like
Highlighted
New Member
1 0 0

To clarify the use of the function to_dict() you can use this function on each object of the Shopify api which has implicit pyactiveresource.

 

For example:

# Get a specific product object
product = shopify.Product.find(179761209)
print(product)
product(179761209)

# Get a specific product object in a dict

product = shopify.Product.find(179761209).to_dict()
print(product)
{ 'id': 179761209
...}
0 Likes