Reputation: 421
I am looking at anisble python API, which returns values via json, which can then be stored as dict
{
"dark" : {
"web1.example.com" : "failure message"
},
"contacted" : {
"web2.example.com" : 1
}
}
I finding it a challenge to dict.get the nested value, of web2.example.com, under contacted.
Thanks in advance. I would give my examples, but they are failing to provide anything usable.
Upvotes: 1
Views: 659
Reputation: 11420
Suppose you get dictionary as follow :-
dictFromJSON = {
"dark" : {
"web1.example.com" : "failure message"
},
"contacted" : {
"web2.example.com" : 1
}
}
Then you can access values as follow :--
for strKey, dictVal in dictFromJSON.items():
if strKey == "contacted":
print dictVal.keys()
Upvotes: 1