I'm having trouble with getting a certain key from a json file in python. I really don't know where to start since I never used json with python before.
[
{
"author": "Chinua Achebe",
"country": "Nigeria",
"imageLink": "images/things-fall-apart.jpg",
"language": "English",
"link": "https://en.wikipedia.org/wiki/Things_Fall_Apart\n",
"pages": 209,
"title": "Things Fall Apart",
"year": 1958
},
{
"author": "Hans Christian Andersen",
"country": "Denmark",
"imageLink": "images/fairy-tales.jpg",
"language": "Danish",
"link": "https://en.wikipedia.org/wiki/Fairy_Tales_Told_for_Children._First_Collection.\n",
"pages": 784,
"title": "Fairy tales",
"year": 1836
}
]
this is a few lines from the json file as an example.
import json
f = open('**\\booksset1.json')
data = json.load(f)
This part loads the json file, but how would I go ahead to get for example one title from the entire file.
datais a list of dicts, akin to what you have in the JSON. You can get the first title like how you would if it were a normal list-of-dicts:data[0]['title']