Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I need to get all these names in the "streamers", but I really don't know how do I do this. 

JSON file:

    "streamers": [

        {},

        {

            "name": "One\n\n"

        },

        {

            "name": "Two\n\n"

        },

        {

            "name": "Three\n\n"

        }

    ]

}

1 Answer

0 votes
by (36.8k points)

You can use the below code:

import json

names=[]

with open('data.txt') as json_file:

  dict=json.load(json_file)["streamers"]

  for tuple in dict:

    if "name" in tuple:

      names.append(tuple["name"]

print(names)

 Want to be a master in Data Science? Enroll in this Data Science Courses

Related questions

Browse Categories

...