I have a json file created by a function.
The file is looks like this :
{"images": [{"image": "/WATSON/VISUAL-REC/../IMAGES/OBAMA.jpg", "classifiers": [{"classes": [{"score": 0.921, "class": "President of the United States", "type_hierarchy": "/person/President of the United States"}, {"score": 0.921, "class": "person"}, {"score": 0.73, "class": "ivory color"}, {"score": 0.648, "class": "Indian red color"}], "classifier_id": "default", "name": "default"}]}], "custom_classes": 0, "images_processed": 1
}
I wrote a function that is going to check is a the value "person" is present. If the value "person" is present, I will increment with
#LOADING MY JSON FILE
output_file = open(new_json_file).read()
output_json = json.loads(output_file)
#SETTING PERSON VALUE TO 0
person = 0
#CONDITIONS
if "person" in output_json["images"][0]["classifiers"][0]["classes"][0]["class"] :person=1print (' FUNCTION : jsonanalysis // step There is a person in this image')return person
else :person = 0print (' FUNCTION : jsonanalysis // step There is a NO person in this image')return person
I guess This is not the right way to check if the value "person" is returned in the JSON Key since it does not find the value. What Am I missing here ?
I looked into some threads like those and tried to adapt my function:
Parsing values from a JSON file using Python?
Find a value within nested json dictionary in python
But my issue is the "class" key. There is several values for the key "class" ( like "ivory color") not just "person".