Nov-23-2022, 10:26 PM
Hello, I am trying to do the following:
1) Read the Json file (sample output attached).
2) If account ID is 4254254 AND "compliance": "Fail", I need to print the respective dictionary.
This is what I have done so far, but it is not working (error explained below):
1) Read the Json file (sample output attached).
2) If account ID is 4254254 AND "compliance": "Fail", I need to print the respective dictionary.
This is what I have done so far, but it is not working (error explained below):
import json RAW_FILE = "to.json" def scanvuln(file,account): # with open (file, 'r') as f: f = open(file, 'r') data = json.load(f) for element in data: print(element) #<== it does print the respective account that are in the json file. OK. if data[account]["cloudformation"]["CloudFormation Drift Detection Analysis"]["analysis_results"][0]["compliance"] == "Fail": print(element) #<== This is simply not working. It does not capture the key/value. Goal is that if that if compliace== "Fail", I should print #the respective section of the dictionary for further analysis. myaccount = "4254254" scanvuln(RAW_FILE, myaccount)Help is appreciated.
Attached Files
to.json (Size: 3.21 KB / Downloads: 119)