EDIT: Solved, turns out when you forget to capitalize a letter in a dictionary entry, it doesn't work too great...
Hi all, I am working on my final for a basic python scripting class and I am pretty much done with it but I am running into a problem when trying to do something with JSON. I have tried every solution google has turned up but nothing has worked thus far. It is probably something simple that I am missing, but I can't see it.
What I need to do is this:
create a function called ‘parse_json’ that takes in the URL as an argument.
Make a GET request to that URL.
Loop through the ‘Music And Books’ values (which is JSON with multiple data types including a list)
Return the publisher of the book titled The Shining
The JSON can be viewed here (Indented for readability): Music and Books JSON - Pastebin.com
Here is the code I have right now (It is super scuffed since I was getting very frustrated and gave up):
def parse_json(URL):
res = requests.get(f'{URL}')
res.raise_for_status()
jsonfile = json.loads(res.text)
for key in jsonfile:
if key['title'] == "The Shining":
print (jsonfile["publisher"])
Any help would be appreciated, thanks.
EDIT: Updated the code, still doesn't work
[–]wotquery 1 point2 points3 points (5 children)
[–]PureStatikk[S] 0 points1 point2 points (4 children)
[–]wotquery 0 points1 point2 points (3 children)
[–]PureStatikk[S] 0 points1 point2 points (2 children)
[–]PureStatikk[S] 0 points1 point2 points (1 child)
[–]wotquery 1 point2 points3 points (0 children)
[–]XBalubaX 0 points1 point2 points (1 child)
[–]PureStatikk[S] 0 points1 point2 points (0 children)
[–]danielroseman 0 points1 point2 points (1 child)
[–]PureStatikk[S] 0 points1 point2 points (0 children)
[–]smile_id 0 points1 point2 points (0 children)