title: Check if key exists and iterate the JSON array using Python
body: <p>I have a bunch of JSON data from Facebook posts like the one below:</p>
  
  <pre><code>{"from": {"id": "8", "name": "Mary Pinter"}, "message": "How ARE you?", "comments": {"count": 0}, "updated_time": "2012-05-01", "created_time": "2012-05-01", "to": {"data": [{"id": "1543", "name": "Honey Pinter"}]}, "type": "status", "id": "id_7"}
  </code></pre>
  
  <p>The JSON data is semi-structured and all is not the same. 
  Below is my code:</p>
  
  <pre><code>import json 
  
  str = '{"from": {"id": "8", "name": "Mary Pinter"}, "message": "How ARE you?", "comments": {"count": 0}, "updated_time": "2012-05-01", "created_time": "2012-05-01", "to": {"data": [{"id": "1543", "name": "Honey Pinter"}]}, "type": "status", "id": "id_7"}'
  data = json.loads(str)
  
  post_id = data['id']
  post_type = data['type']
  print(post_id)
  print(post_type)
  
  created_time = data['created_time']
  updated_time = data['updated_time']
  print(created_time)
  print(updated_time)
  
  if data.get('application'):
      app_id = data['application'].get('id', 0)
      print(app_id)
  else:
      print('null')
  
  #if data.get('to'):
  #... This is the part I am not sure how to do
  # Since it is in the form "to": {"data":[{"id":...}]}
  </code></pre>
  
  <p>I want the code to print the <em>to_id</em> as 1543 else print 'null'</p>
  
  <p>I am not sure how to do this.</p>