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
#4
Thanks a bunch, @bowlofred ! I was unsure of how to use for-loop in this case, but with your example I now know a real-world case for using them. Plus, now I've learned about Formatted string literals :-)

@snippsat Thanks, now my program is even more slim. All in all, my code is as below. Do you see anything I could improve in it to follow good practices? I do need to assign a value to response variable, but do I need to load the json into input_json and latter to input_json_keyfilter ?

Thanks again Smile

import requests
response = requests.get('https://api.resrobot.se/v2/departureBoard?key=REDACTED')
input_json = response.json()
input_json_keyfilter = input_json.get("Departure")
for line in input_json_keyfilter:
    print(f" {line['transportNumber']} -> {line['direction']}")
    print(f"      {line['time']}")
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 serpiente - Mar-14-2021, 07:01 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,481 Apr-12-2023, 08:10 PM
Last Post: deanhystad
  Printing string at specific position on terminal - not showing __Mathieu__ 1 2,419 Sep-07-2020, 10:32 AM
Last Post: Larz60+
  Monitor specific line of code from website Olimpiarob 1 1,869 Jul-09-2020, 03:20 PM
Last Post: mrdominikku
  update txt file but keep a specific line 3Pinter 2 2,119 Dec-16-2019, 07:54 AM
Last Post: 3Pinter
  extract specific data from a group of json-files ledgreve 3 3,323 Dec-05-2019, 07:57 PM
Last Post: ndc85430
  Delete specific lines contain specific words mannyi 2 4,184 Nov-04-2019, 04:50 PM
Last Post: mannyi
  insert value to specific line in CSV file asheru93 1 1,805 Oct-21-2019, 03:37 PM
Last Post: Larz60+
  Finding a specific line in a file Vqlk 3 2,626 Sep-07-2019, 08:20 PM
Last Post: Axel_Erfurt
  Python start from a specific string line and write? searching1 1 2,245 Jun-27-2019, 02:28 PM
Last Post: perfringo
  Printing List in one line bharat_s579 6 4,190 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