(Nov-23-2022, 03:24 AM)deanhystad Wrote: It is just a list of dictionaries inside a dictionary inside a dictionary inside a .... Wow, that is a bad looking data structure.That's how data structure are many times coming from largere API resonse in Json format,i would not say it's bad structure.
The data comes for AWS CloudFormation
(Nov-23-2022, 02:31 AM)mrapple2020 Wrote: .The
I ran the code below and it executes. Can you do me a favor and point out from here how can I retrieve the value of the "compliance" key?
RAW_DATA
may already been encoded for use in Python,how are you getting the data?Also for output to work on site DeaD_EyE postet have to this like this to get double quotation marks.
Or as mention just the
RAW_DATA
that's in string could be used if as it's alradt a dictionary put in a string.import json from nested_lookup import nested_lookup def new_func(): RAW_DATA = """ {"131998795651": { "cloudformation": { "CloudFormation Drift Detection Analysis": { "analysis_results": [{ "account_id": "131998795651", "analysis_scope": "Service", "analyzer_name": "CloudFormation Drift Detection Analysis", "compliance": "Pass", "evidence": "Cloudformation stack is in sync for drift detection." }]}}}}""" return RAW_DATA RAW_DATA = new_func() data = json.loads(RAW_DATA) js_data = json.dumps(data, indent=2) print(js_data)Now can copy data into Json Crack
Output:{
"131998795651": {
"cloudformation": {
"CloudFormation Drift Detection Analysis": {
"analysis_results": [
{
"account_id": "131998795651",
"analysis_scope": "Service",
"analyzer_name": "CloudFormation Drift Detection Analysis",
"compliance": "Pass",
"evidence": "Cloudformation stack is in sync for drift detection."
}
]
}
}
}
}
See also that i have imported nested_lookup,this make it easy to search direclity in a nested stucture like this.>>> nested_lookup("compliance", data) ['Pass']So the same result as deanhystad break down into the dictionary.
>>> data["131998795651"]["cloudformation"]["CloudFormation Drift Detection Analysis"]["analysis_results"][0]["compliance"] 'Pass'