title: How to check if a particular dictionary exists in a file
body: <p>I need to know if a dictionary named 'behavior' with a key named apistats exists in my json file that i am opening so that if it exists I can do further processing, and if it doesnt exist so the next file opens</p>
  
  <p>I have tried putting condition if dictionary with apistats exist or not , but it gives error.
  Also I can't put a check on only the key apistats in behavior, because for some files behavior dictionary doesnt exist at all</p>
  
  <pre><code>    for filename in glob.glob('*.json'):
               with open(filename) as json_file:
                        data=json.load(json_file)
                        if data['behavior']['apistats']:
                                print ('exists')
                        else:
                        print("doesn't")
  
  
      Expected:
      exists
      exists
      doesn't
      Actual Output: 
      File "C:/Users/sidra/Desktop/extractor/ectractor.py", line 12, in &lt;module&gt;
      if data['behavior']['apistats']:
  
      KeyError: 'apistats'
  </code></pre>