I have a json file as follows:
{
"Alib": {
"depends": null,
"locked": false,
"stage": "xyz",
"version": "1.2.3"
}
"Blib": {
"depends": null,
"locked": false,
"stage": "abc",
"version": "4.3.8"
}
"clib": {
"depends": null,
"locked": false,
"stage": "def",
"version": "5.2.6"
}
}
Now i want to read this json file in a way that i get the lib name and the version with respect to that lib. Currently i have solution as follows:
with open (jsonfile) as data_file:
file = json.load(data_file)
print file["alib"]["version"]
print file["blib"]["version"]
print file["clib"]["version"]
I do get the details of the each lib version but this is not exactly what i want. I dont want to provide the name of the lib hardcoded into the code. It should be something like :
with open (jsonfile) as data_file:
file = json.load(data_file)
print file[lib]["version"]
and i get the names of the lib along with there versions independently. So, please suggest how shall i acheive this kind of solution where i don't provide the names of the libs and make more generic.