0

I just wanted to ask what can I do to solve this issue I have.

Essentially I am making a stock checker for sneakers from Adidas, I know the endpoint to obtain the stock but the JSON data given back to me whilst readable and contains what I need also contains a bunch of other information that is unnecessary to what I am trying to do.

Example of a link to an endpoint:

http://production.store.adidasgroup.demandware.net/s/adidas-GB/dw/shop/v16_9/products/(BZ0221)?client_id=c1f3632f-6d3a-43f4-9987-9de920731dcb&expand=availability,variations,prices

This is a link to the JSON containing the stock of the shoe, price and availability. However, if you try to open it you'll see that it responds a bunch of useless info such as the description of the shoe and the price which I do not need.

A github repository that I was using to try and get to grips with the requests I am trying to make is:

https://github.com/yzyio/adidas-stock-checker/blob/master/assets/index.js

I can get it to give me the JSON response I am just trying to strip what I don't need and keep what I do need which I am finding very difficult especially in python.

Many Thanks!

3

1 Answer 1

2

Since you've said you can get a JSON response from the server than the first think you need to do is tell python to load it as JSON.

import json
data = json.loads(response_from_server)

After doing this you can now access the values in your JSON object the way you would access them via a Python dict.

data["artist"]["id"]
Sign up to request clarification or add additional context in comments.

4 Comments

Hi, I tried doing thsi with the objects "name" and "variants" as a test but I end up getting this TypeError: the JSON object must be str, bytes or bytearray, not 'Response'
That means response_from_server is not a string, try evaluating what type of object this is.... if it's a response object than you may need to say data = json.loads(response_from_server.text)
see this question for more information. stackoverflow.com/questions/42976090/…
It's best to use .content, .text will try to decode the response. Or even better use .json() which returns a json object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.