[Solved] How can I get ‘key’ and ‘value’ from parsed JSON in python [closed]


What you receive when you load json data, is native Python Dict, or List.
When you’re iterating over a list of dictionaries as you do here, data is a dict.

To extract a value from a dict, you need to look up the key by its name, in your instance: 'minecraft.net', 'session.minecraft.net', 'account.mojang.com', ...

Python dictionaries are accessed like so: data["minecraft.net"] (returns “green”)

Easiest to do would be (following your setup):

for data in json:
    for key, value in data.items():
        print(key)
        print(value)

Essentially:

for dictionary in list:
    for key, value in dictionary.items():
        print(key)
        print(value)

Read more: w3schools: Python Loop Through a Dictionary

(edit): Summary

Unclear in the question, but variable ‘json’ was a file-like object.
Resolved issue with:

json = json.load(json)

7

solved How can I get ‘key’ and ‘value’ from parsed JSON in python [closed]