Skip to content
Advertisement

Convert Json format String to Link{“link”:”https://i.imgur.com/zfxsqlk.png”}

I try to convert this String to only the link: {"link":"https://i.imgur.com/zfxsqlk.png"}

I’m trying to create a discord bot, which sends random pictures from the API https://some-random-api.ml/img/red_panda.

With imageURL = json.loads(requests.get(redpandaurl).content) I get the json String, but what do I have to do that I only get the Link like this https://i.imgur.com/zfxsqlk.png

Sorry if my question is confusingly written, I’m new to programming and don’t really know how to describe this problem.

Advertisement

Answer

You can simply do this:

image_url = requests.get(your_api_url).json()["link"]

Directly use requests.json(), no need to load the string with json.loads and other manual stuff.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement