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

How to read multiple curly brackets with json in python?

I need a way to read multiple curly brackets in python. I have a test json that has multiple layers of curly brackets and I need to get to the deepest layer. My test json: my json (I need it to return "name". My code isn’t working, but this is what it looks like (not all of it, just the important parts.)

import json 
    
with open(args.mc_path + "launcher_profiles.json", "r+") as profiles:
    data = json.load(profiles)

test = data["profiles": { "053abfb0fb7451c291b9149ea7df88c8": {"name"}}]
print(test)

>Solution :

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

You can index on nested dictionaries multiple times to get the nested value.
In your case that would look like:

test = data["profiles"]["053abfb0fb7451c291b9149ea7df88c8"]["name"]
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