Parsing JSON string from URL with Python 3.5.2
<p>I am trying to print out the values <code>"lat"</code> and <code>"lon"</code> from the JSON (<a href="https://en.wikipedia.org/w/api.php?action=query&amp;format=json&amp;prop=coordinates&amp;list=&amp;titles=venice" rel="nofollow">source</a>):</p>

<pre class="lang-js prettyprint-override"><code>{
    "batchcomplete": "",
    "query": {
        "normalized": [
            {
                "from": "venice",
                "to": "Venice"
            }
        ],
        "pages": {
            "32616": {
                "coordinates": [
                    {
                        "globe": "earth",
                        "lat": 45.4375,
                        "lon": 12.33583333,
                        "primary": ""
                    }
                ],
                "ns": 0,
                "pageid": 32616,
                "title": "Venice"
            }
        }
    }
}
</code></pre>

<p>This is my code that I supposed to work:</p>

<pre><code>import urllib.request as url
import json
import urllib.parse
import ast

request = url.Request('https://en.wikipedia.org/w/api.php?action=query&amp;format=json&amp;prop=coordinates&amp;list=&amp;titles=venice')
data = url.urlopen(request).read()
data = data.decode("utf-8")
data = ast.literal_eval(data)
data = json.dumps(data)
array = json.loads(data)
#print(array)
print(array['query']['pages']['32616']['coordinates']['lat'+','+'lon'])
</code></pre>

<p>It returns the error: <code>TypeError: list indices must be integers or slices, not str</code>.</p>

<pre><code>print(array['query']['pages']['32616']['coordinates'][0]['lat'])
print(array['query']['pages']['32616']['coordinates'][0]['lon'])
                                               insert ^
</code></pre>

python