title: How To Format a JSON Text In Python?
body: <p>When I call the JSON file for Vincent van Gogh's List of Works wikipedia page, using <a href="http://en.wikipedia.org/w/api.php?format=json&amp;action=query&amp;titles=list%20of%20works%20by%20Vincent%20van%20Gogh&amp;Page&amp;prop=revisions&amp;rvprop=content" rel="nofollow">this</a> url,
  it obviously returns a huge blob of text which I believe is some sort of dictionary of lists. </p>
  
  <p>Now, someone has already shown me Python's import wikipedia feature, so skip that. How can I decode this JSON? I feel like I have tried everything in Python 3's library, and always get an error, like I get if I try this code for example:</p>
  
  <pre><code>data = urllib.request.urlopen(long_json_url)
  stuff = json.load(data)   #or json.loads(data)
  print(stuff)
  </code></pre>
  
  <p>it returns</p>
  
  <pre><code>TypeError: the JSON object must be str, not 'bytes'
  </code></pre>
  
  <p>Or if I try this code:</p>
  
  <pre><code>data = urllib.request.urlopen(longurl)
  json_string = data.read().decode('utf-8')
  json_data = json.loads(json_string)
  print(json_data)
  </code></pre>
  
  <p>It doesn't return an error, but just what looks like nothing</p>
  
  <pre><code>&gt;&gt;&gt;
  
  &gt;&gt;&gt;
  </code></pre>
  
  <p>But if I highlight that empty space and paste it, it pastes the same blob of text. </p>
  
  <p><code>{'warnings': {'main': {'*': "Unrecognized parameter: 'Page'"}}, 'query': {'normalized': [{'from': 'list of works by Vincent van Gogh',</code>... etc</p>
  
  <p>If I try a for loop:</p>
  
  <pre><code>for entry in json_data:
      print(entry)
  </code></pre>
  
  <p>It returns</p>
  
  <pre><code>&gt;&gt;&gt; 
  query
  warnings
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>And that's it. So it's not returning an error there, but not really much else, just two values? How would you make the JSON data into a workable Python dict or list? Or at the very least, into a more vertical format that I could actually read?</p>