Mar-14-2021, 07:27 PM
Add empty list as default value in
get()
. If your json has no Departure
key, the get()
method will prevent KeyError
only to to get TypeError
on the next line because NoneType is not iterable.input_json_keyfilter = input_json.get("Departure", [])also, there is no problem to do directly
input_json = response.json() for line in input_json.get("Departure", []):
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs