title: iterating through json with python
body: <p>I have learning python for a few months now, doing several online courses a now started on my own project. I have found an interesting website which provided data in a json-format which I import using the urllib library, parse using the json library and eventually want to insert this into an mysql database. The first and the last part of this project work, but not the parsing part. This is a part of the full json file:</p>
  
  <pre><code>{
  "total": 24555,
  "results": {
      "type": "FeatureCollection",
      "features": [
          {
              "type": "Feature",
              "geometry": null,
              "id": "556897c8b9a2143b1187cf79",
              "properties": {
                  "Expedition": "okavango_15",
                  "SpeciesName": "African Hoopoe",
                  "Count": 1,
                  "t_utc": 1325383950,
                  "t_created": 1432917960.344582,
                  "Member": "Maans",
                  "Taxonomy": {
                      "Kingdom": "Animalia",
                      "Species": "Upupa epops",
                      "Family": "Upupidae",
                      "Genus": "Upupa",
                      "Phylum": "Chordata",
                      "Order": "Upupiformes",
                      "Class": "Aves"
                  },
                  "FeatureType": "sighting",
                  "Images": [],
                  "DateTime": "2012-01-01T04:12:30+0200",
                  "EstimatedGeometry": null,
                  "Behavior": "Flying",
                  "Habitat": "Mioambo Woodland"
              }
          },
          {
              "type": "Feature",
              "geometry": null,
              "id": "556897b2b9a2143b1d14a807",
              "properties": {
                  "Expedition": "okavango_15",
                  "SpeciesName": "Peregrine Falcon",
                  "Count": 1,
                  "t_utc": 1325406263,
                  "t_created": 1432917938.878641,
                  "Member": "Maans",
                  "Taxonomy": {
                      "Kingdom": "Animalia",
                      "Species": "Falco peregrinus",
                      "Family": "Falconidae",
                      "Genus": "Falco",
                      "Phylum": "Chordata",
                      "Order": "Falconiformes",
                      "Class": "Aves"
                  },
                  "FeatureType": "sighting",
                  "Images": [],
                  "DateTime": "2012-01-01T10:24:23+0200",
                  "EstimatedGeometry": null,
                  "Behavior": "Flying",
                  "Habitat": "Mioambo Woodland"
              }
          },
          {
              "properties": {
                  "SpeciesName": "Reed Cormorant",
                  "Count": 1,
                  "Accuracy": 8.0,
                  "Expedition": "okavango_13",
                  "t_created": 1430929467.352914,
                  "Member": null,
                  "FeatureType": "sighting",
                  "Altitude": 973.2047942238661,
                  "t_utc": 1378449600,
                  "DateTime": "2013-09-06T08:40:00+0200",
                  "Activity": "L",
                  "SightingId": 0
              },
              "geometry": {
                  "type": "Point",
                  "coordinates": [
                      22.345429148371103,
                      -19.018043140479318
                  ]
              },
              "id": "554a403bb9a21401a231284f",
              "type": "Feature"
          }
      ]
  },
  "resolution": "full",
  "filter": {
      "FeatureType": "sighting"
  },
  "returned": 3,
  "order": 1,
  "limit": 3
  </code></pre>
  
  <p>}</p>
  
  <p>For parsing the json file I use this code:</p>
  
  <pre><code>import json
  
  def remove_nulls(d):
      return {k: v for k, v in d.iteritems() if v is not None}
  
  with open('okavango.json') as fhand:
      data = json.loads(fhand.read(), object_hook=remove_nulls)
  </code></pre>
  
  <p>The level which I want to get the data from is in "features", which contains animal sightings with a lot of other keys like species name, timestamp, location. The various sightings don't always contain the same keys, location for example is not always present. I do want to parse the data sighting by sighting thought since I want it to be a single rows in my database. I am able to get every single bit of data I want by calling each individual item using this kind of code:</p>
  
  <pre><code>results = data["results"]
  
  for item in results["features"]:
      value1 = item["id"]
      value2 = item["properties"]["t_created"]
  </code></pre>
  
  <p>But this makes my code very long and it should be easier to iterate i guess. However, I am not able to get single key/value results for each single . I have used the .get function, .values etc. but it turns out that not every level in my json file is a dictionary, but something it is a list. If I run this code for example:</p>
  
  <pre><code>print type(data)
  data2 = data["results"]
  print type(data2)
  data3 = data2["features"]
  print type(data3)
  </code></pre>
  
  <p>my result is this:
  type 'dict'
  type 'dict'
  type 'list'</p>
  
  <p>How do I iterate through the original json load and parse the data by sighting?</p>