Im dealing with a large json file that has many boolean values, so I cant just search on the value alone. How can I extract the entire user information if one value is true?
For example the json file has many lines that could read something like this:
[
12,
{
"name": "Big Bird",
"muting": false,
"following": true,
"blocked_by": false,
"followers_count": 42
}
]
How can I iterate through the file to find all users who could be set to muting as true?
The code I have is
import json
with open("tempList") as f:
data = json.load(f)
for key in data:
if key['muting'] == "false":
print("YES")
else:
print("$*%#!@")
2
Answers
Since it appears some values for
user
will be integers, we can explicitly check the type ofuser
to avoid problems; also, using.get
to access the dict will avoidKeyError
if the key is not present. Thus:For the first question
How can I extract the entire user information if one value is true?