Answer the question
In order to leave comments, you need to log in
How can one access a key in a json dictionary through python?
I need to do a check if a key is in a dictionary in a json file.
import json
id = "2"
dict = json.load(open('C:/Users/ilyaf/Desktop/py-proj/Code Bot/assets/main.json'))
if id == dict.get(id):
print('id in dict!')
{
"id":"2",
"money":"100",
"reputation":"0"
}
Answer the question
In order to leave comments, you need to log in
It seems like your id in json is a string, and you are trying to compare it with an integer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question