Help with nested dictionaries (I think) Need help pulling out specific value (have done google searching to no avail)

Ok, so i’m using an api that returns a dictionary that looks something like this:

random = {'random': 332, 'Id': 11, 'Mode': 'CLASSIC', 'Type': 'CUSTOM', 'participants': [{'Id': 100, 'Id': 14, '2Id': 4, 'cId': 1, 'IconId': 4245, 'Name': 'agaming83', 'bot': False, 'sId': 'F0IWXeoB', 'gCustomObjects': [], 'perks': {'perkIds': [8351, 8304, 8345, 8347, 8014, 9104, 5008, 5008, 5002], 'pStyle': 8300, 'pSubStyle': 8000}}], 'observers': {'encryptionKey': 'HNI11xmLmb6p+o2uDNKE/oFJffZDNDvb'}, 'formId': 'A1', 'bChamp': [], 'StartTime': 0, 'Length': 0}

I want to get the Name agaming83 from this dict. I have tried things like:

Print(random['participants']['Name'])
for key, value in random.items() :
    print (key, value)

and nothing extracts the specific thing I want. Any help would be awesome.

I am able to do something like this:

random2 = test[‘participants’]
print(random2)

and am able to get a everything from the participants key, but I want to get just the specific value of agaming83 from the dict

If I made something confusing let me know and i’ll clarify

(side note please be gentle I am very new to python)Preformatted text

random['participants'] seems to be an array, so first we need to access the element in the array we want:

random['participants'][0]

now we have access to the first element array (which is a dictionary), we can again use a key to get the name:

random['participants'][0]['Name']

ideally, you don’t want to hard-code array indices, so that is where you could use a loop:

for (const participant of random['participants'])
{

}
1 Like