I have these horrible nested JSON dictionaries:
"data": {
"assetID": "VMSA0000000000310652",
"lastModified": "2017-06-02T19:36:36.535-04:00",
"locale": {
"MetadataAlbum": {
"Artists": {
"Artist": {
"ArtistName": "Various Artists",
"ArtistRole": "MainArtist"
}
},
"Publishable": "true",
"genres": {
"genre": {
"extraInfos": null,
}
},
"lastModified": "2017-06-02T19:32:46.296-04:00",
"locale": {
"country": "UK",
"language": "en",
And want to be able to match the value of the language with the method below. I am passing in language ('en') and the data is the nested dictionary above.
def get_localized_metadataalbum(language, data):
for locale in data['locale']:
if data['locale'].get('MetadataAlbum') is not None:
if data['locale'].get('MetadataAlbum').get('locale') is not None:
if data['locale'].get('MetadataAlbum').get('locale').get('language') is not None:
if data['locale'].get('MetadataAlbum').get('locale').get('language') == language:
return data['locale']
return None
The method works with a list of dictionaries, but not with dictionaries inside dictionaries... Can anyone point me to a place where I can learn how to parse through nested dictionaries? I'm a little lost here and all examples I've found show how to parse to a list of dictionaries.
I've been getting: TypeError: string indices must be integers