Back
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" } ]}
"streamers": [
{},
{
"name": "One\n\n"
},
"name": "Two\n\n"
"name": "Three\n\n"
}
]
You can use the below code:
import jsonnames=[]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)
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
31k questions
32.8k answers
501 comments
693 users