title: skipping a json key if does not exist
body: <p>I'm running the following:</p>
  
  <pre><code>for server in server_list:
      for item in required_fields:
          print item, eval(item)
  </code></pre>
  
  <p>There is a possibility that some keys may not exist, but worse it's represented on a parent key not the one I'm scanning for.</p>
  
  <p>So I'm scanning the json for the following key:</p>
  
  <pre><code>server['server_management']['server_total_cost_of_ownership']['description']
  </code></pre>
  
  <p>Which doesn't exist but it's actually the parent that is null:</p>
  
  <pre><code>server['server_management']['server_total_cost_of_ownership']
  </code></pre>
  
  <p>How do I write my code to account for this?  It's not giving a key error.  Right now I get the following traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/projects/blah/scripts/test.py", line 29, in &lt;module&gt;
      print item, eval(item)
    File "&lt;string&gt;", line 1, in &lt;module&gt;
  TypeError: 'NoneType' object has no attribute '__getitem__'
  </code></pre>
  
  <p>Full code:</p>
  
  <pre><code>import csv
  import json
  import os
  import requests
  import sys
  
  required_fields = ["server['server_name']","server['server_info']['asset_type']['display_name']",
                     "server['asset_status']['display_name']", "server['record_owner']['group_name']",
                     "server['server_management']['server_total_cost_of_ownership']['description']",
                     "server['server_management']['primary_business_owner']['name']",
                     "server['environment']['display_name']", "server['is_virtual']",
                     "server['managed_by']['display_name']", "server['server_info']['billable_ibm']",
                     "server['server_info']['billing_sub_type']['display_name']",
                     "server['server_info']['serial_number']", "server['location']['display_name']",
                     "server['inception_date']", "server['server_info']['decommission_date']" ]
  
  # Query API for all servers
  def get_servers_info():
      servers_info = requests.get('url')
      return servers_info.json()
  
  def get_server_info(sid):
      server_info = requests.get('url')
      return server_info.json()
  
  server_list = get_servers_info()
  for server in server_list:
      for item in required_fields:
          print item, eval(item)
  </code></pre>