JSON sub for loop produces KeyError, but key exists
<p>I'm trying to add the JSON output below into a dictionary, to be saved into a SQL database.</p>

<pre><code>{'Parkirisca': [
    {    
    'ID_Parkirisca': 2,
    'zasedenost': {
                   'Cas': '2016-10-08 13:17:00',
                   'Cas_timestamp': 1475925420,
                   'ID_ParkiriscaNC': 9,
                   'P_kratkotrajniki': 350
                  }
    }
]}
</code></pre>

<p>I am currently using the following code to add the value to a dictionary:</p>

<pre><code>import scraperwiki
import json
import requests
import datetime
import time
from pprint import pprint

html = requests.get("http://opendata.si/promet/parkirisca/lpt/")

data = json.loads(html.text)

for carpark in data['Parkirisca']:

    zas = carpark['zasedenost']
    free_spaces = zas.get('P_kratkotrajniki')
    last_updated = zas.get('Cas_timestamp')

    parking_type = carpark.get('ID_Parkirisca')
    if parking_type == "Avtomatizirano":
        is_automatic = "Yes"
    else:
        is_automatic = "No"

    scraped = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')

    savetodb = {
    'scraped': scraped,
    'id': carpark.get("ID_Parkirisca"),
    'total_spaces': carpark.get("St_mest"),
    'free_spaces': free_spaces,
    'last_updated': last_updated,
    'is_automatic': is_automatic,
    'lon': carpark.get("KoordinataX_wgs"), 
    'lat': carpark.get("KoordinataY_wgs")
    }

    unique_keys = ['id']

    pprint savetodb
</code></pre>

<p>However when I run this, it gets stuck at <code>for zas in carpark["zasedenost"]</code> and outputs the following error:</p>

<pre><code>Traceback (most recent call last):
File "./code/scraper", line 17, in &lt;module&gt;
    for zas in carpark["zasedenost"]:
KeyError: 'zasedenost'
</code></pre>

<p>I've been led to believe that <code>zas</code> is in fact now a string, rather than a dictionary, but I'm new to Python and JSON, so don't know what to search for to get a solution. I've also searched here on Stack Overflow for <code>KeyErrror when key exist</code> questions, but they didn't help, and I believe that this might be due to the fact that's a sub for loop.</p>

<p>Update: Now, when I swapped the double quotes for single quotes, I get the following error:</p>

<pre><code>Traceback (most recent call last):
File "./code/scraper", line 17, in &lt;module&gt;
    free_spaces = zas.get('P_kratkotrajniki')
AttributeError: 'unicode' object has no attribute 'get'
</code></pre>