Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Accessing unique json array

I’m aware the code won’t work because i can’t work out how to access each array.
Person-Ryan, Personal-Luke.
There will be multiple and each will be unique and won’t know what they be called beforehand.

I would like to print the name on each one in a loop.

Json:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"entities": {
    "Person-Ryan": {
        "name":"Ryan"
    },
    "Person-Luke": {
        "name": "Luke"
   }
}

Code:

res_json = response.json()

for inner_dict in res_json:
    Test = inner_dict['name']
    print (Test)

>Solution :

I think what you need is just calling items function on the dictionary that you get from response.json():

for key, value in res_json["entities"].items():
  print(value["name"])

Output

Ryan
Luke
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading