Python Forum
Json filter is not capturing desired key/element
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Json filter is not capturing desired key/element
#2
If you don't understand what your program is doing, always add print statements to see the progress in more detail. In this case you wonder why your "if" statement is not working. Just print the condition before the "if":
print(data[account]["cloudformation"]["CloudFormation Drift Detection Analysis"]["analysis_results"][0]["compliance"])
Output:
Pass
As "Pass" is not "Fail" nothing is printed.

Also it is strange you iterate over the elements (in your example there is only one element at toplevel) but you test always the same element: "data[account]". I think you want to test "data[element]".
Reply


Messages In This Thread
RE: Json filter is not capturing desired key/element - by ibreeden - Nov-24-2022, 09:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Capturing BS4 values into DF and writing to CSV cubangt 18 1,940 Sep-05-2023, 01:57 PM
Last Post: cubangt
  capturing multiline output for number of parameters jss 3 805 Sep-01-2023, 05:42 PM
Last Post: jss
  how can I display only desired items? 3lnyn0 5 2,014 Dec-25-2021, 06:49 PM
Last Post: menator01
  ERROR: importing desired module mbgamer28 0 1,669 Apr-05-2021, 07:46 PM
Last Post: mbgamer28
  how to filter two fields in json using python python_student 4 3,654 Mar-15-2021, 05:58 PM
Last Post: python_student
  Not rounding to desired decimal places? pprod 2 2,534 Mar-05-2021, 11:11 AM
Last Post: pprod
  Why this code not getting desired output ? MDRI 2 2,514 Sep-18-2020, 02:11 AM
Last Post: MDRI
  showing only desired part of a plot grknkilicaslan 1 2,325 Jul-10-2020, 03:51 PM
Last Post: Marbelous
  [Beginner] Code is not producing desired result fakej171 2 2,421 Mar-21-2020, 10:26 AM
Last Post: buran
  Not Getting the Desired value using json.dumps saurabh210 0 1,491 Feb-03-2020, 06:48 PM
Last Post: saurabh210

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020