title: Receiving "KeyError" after decoding json result from url
body: <p>I am new to Python. I am trying to parse the json result from a url. Originally, I was using the following:</p>
  
  <pre><code>response = urllib.request.urlopen(url)
  json_obj = json.load(response)
  </code></pre>
  
  <p>This gave an error along the lines of "JSON object should be 'str' not 'bytes'" so, after searching on stackoverflow, I decoded the response as follows:</p>
  
  <pre><code>f = urllib.request.urlopen(url)
  charset = f.info().get_param('charset', 'utf8')
  data = f.read()
  decoded = json.loads(data.decode(charset))
  </code></pre>
  
  <p>If I print "decoded" it is as follows:</p>
  
  <pre><code>{'Links': {'SummaryData': 'https://localhost/piwebapi/streams/P0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTExNQU42NDIwXFNJTlVTT0lE/summary', 'Value': 'https://localhost/piwebapi/streams/P0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTExNQU42NDIwXFNJTlVTT0lE/value', 'InterpolatedData': 'https://localhost/piwebapi/streams/P0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTExNQU42NDIwXFNJTlVTT0lE/interpolated', 'Self': 'https://localhost/piwebapi/points/P0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTExNQU42NDIwXFNJTlVTT0lE', 'PlotData': 'https://localhost/piwebapi/streams/P0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTExNQU42NDIwXFNJTlVTT0lE/plot', 'DataServer': 'https://localhost/piwebapi/dataservers/s0_7qHaW4UHU-RlCaz8tpasAU0hJTExNQU42NDIw', 'RecordedData': 'https://localhost/piwebapi/streams/P0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTExNQU42NDIwXFNJTlVTT0lE/recorded'}, 'Id': 1, 'Name': 'SINUSOID', 'WebId': 'P0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTExNQU42NDIwXFNJTlVTT0lE'}
  </code></pre>
  
  <p>Now, whenever I try to pull out a particular value, I get a "KeyError". For example:</p>
  
  <pre><code>print(decoded[0])
  </code></pre>
  
  <p>returns the following:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensio
  ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 1
  06, in exec_file
      exec_code(code, file, global_variables)
    File "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensio
  ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 8
  2, in exec_code
      exec(code_obj, global_variables)
    File "C:\Users\shillman\Documents\Visual Studio 2010\Projects\PythonApplicatio
  n1\PythonApplication1\PythonApplication1.py", line 26, in &lt;module&gt;
      print(decoded[0])
  KeyError: 0
  </code></pre>
  
  <p>What format is "decoded" in? Is there a way I can do this where it is actually a dictionary? Is there a way to convert it to a dictionary? Any help/advice is greatly appreciated! Thank you.</p>