I'm working on a script with Python that will generate a joke using an API I found online. (https://sv443.net/jokeapi/v2/). However, some of the setup/question parts of the joke use JSON Data, which varies between being 'setup' and 'joke'. I'm looking to see if I can write a script that will check which one the response is pulling. I have my script here:
import requests
import json
def getJoke():
response = requests.get("https://v2.jokeapi.dev/joke/Any")
print(response.text)
json_data = json.loads(response.text)
joke = json_data['joke'] + json_data['setup'] + " " + json_data['delivery']
print(joke)
getJoke()
Some of the responses are
"error": false,
"category": "Christmas",
"type": "twopart",
"setup": "How will Christmas dinner be different after Brexit?",
"delivery": "No Brussels!",
and
"error": false,
"category": "Programming",
"type": "twopart",
"joke": "Why is Linux safe?",
"delivery": "Hackers peak through Windows only.",
Is there a way to check which data-name the response is getting?