title: Python KeyError when iterating dict from JSON-file
body: <p>I'm trying to read a JSON file (and eventually save the contents to a database), but I'm getting an KeyError when running the code below. <a href="http://pastebin.com/JSj0rLrY" rel="nofollow noreferrer">See sample JSON</a> for reference.</p>
  
  <p>The keys <code>'durationTimeFrom'</code> and <code>'durationTimeTo'</code> does not exist in all cases in the JSON file (only when <code>eventType</code> is <code>80</code>, I think).</p>
  
  <p>How do I properly identify missing keys before attempting to read the value, and/or how do I insert dummy-keys for the items that do not have the key already?</p>
  
  <p>I have already searched Google/StackOverflow and tried <code>if key in dict:</code> and <code>dict.get(key)</code> without success.</p>
  
  <pre><code>import json
  
  source = "feed_traffic.json" # JSON file to process
  data = json.loads(open(source).read()) # Process JSON
  
  total = data["events"]["totalCount"]
  index = 0
  
  events = data["events"]["list"][index:total]
  
  for event in events:
  
      eid = event["id"]
      type = event['eventType']
      header = event['headingText']
      lat = event['latitude']
      long = event['longitude']
      created = event['created']
      updated = event['updated']
      expires = event['expireTime']
      validFrom = event['durationTimeFrom']
      validTo = event['durationTimeTo']
      status = event['status']
  
      # Just to check all is well, out data in console
      print("Traffic Event", index, ":", eid, "-", type, "-", header, "(", long, ",", lat, ")")
  
      index = index+1
  </code></pre>