Python Forum
Printing a specific line from a JSON
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing a specific line from a JSON
#5
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

Reply


Messages In This Thread
Printing a specific line from a JSON - by serpiente - Mar-13-2021, 08:47 PM
RE: Printing a specific line from a JSON - by buran - Mar-14-2021, 07:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing specific values out from a dictionary mcoliver88 6 1,423 Apr-12-2023, 08:10 PM
Last Post: deanhystad
  Printing string at specific position on terminal - not showing __Mathieu__ 1 2,394 Sep-07-2020, 10:32 AM
Last Post: Larz60+
  Monitor specific line of code from website Olimpiarob 1 1,853 Jul-09-2020, 03:20 PM
Last Post: mrdominikku
  update txt file but keep a specific line 3Pinter 2 2,089 Dec-16-2019, 07:54 AM
Last Post: 3Pinter
  extract specific data from a group of json-files ledgreve 3 3,303 Dec-05-2019, 07:57 PM
Last Post: ndc85430
  Delete specific lines contain specific words mannyi 2 4,148 Nov-04-2019, 04:50 PM
Last Post: mannyi
  insert value to specific line in CSV file asheru93 1 1,788 Oct-21-2019, 03:37 PM
Last Post: Larz60+
  Finding a specific line in a file Vqlk 3 2,596 Sep-07-2019, 08:20 PM
Last Post: Axel_Erfurt
  Python start from a specific string line and write? searching1 1 2,227 Jun-27-2019, 02:28 PM
Last Post: perfringo
  Printing List in one line bharat_s579 6 4,155 May-26-2019, 08:30 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020