Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first thing I would do when working with a big lump of json, is try to get it into a more readable format. <a href="http://jsonformatter.curiousconcept.com" rel="noreferrer">This online json formatting tool</a> should do the job.</p> <p>Here's some code that will get all the trend names:</p> <pre><code>import urllib2 import json url = 'http://api.twitter.com/1/trends/44418.json' # download the json string json_string = urllib2.urlopen(url).read() # de-serialize the string so that we can work with it the_data = json.loads(json_string) # get the list of trends trends = the_data[0]['trends'] # print the name of each trend for trend in trends: print trend['name'] </code></pre> <p>Or you can do it all in one line:</p> <pre><code>names = [trend['name'] for trend in the_data[0]['trends']] for name in names: print name </code></pre> <p>Both will result in:</p> <pre> #throwagrenade Rebecca Black Eric Abidal #questionsihate #juniordoctors Smiley Culture Lily Allen Wes Brown Pandev Ray Wilkins </pre> <p><strong>Relevant reading:</strong></p> <p><a href="http://docs.python.org/library/json.html" rel="noreferrer">Python docs on json</a> (although you should only really need <code>json.loads()</code>)</p> <p><a href="http://diveintopython.net/" rel="noreferrer"><em>Dive Into Python</em></a>'s sections on <a href="http://diveintopython.net/getting_to_know_python/lists.html" rel="noreferrer">lists</a> and <a href="http://diveintopython.net/getting_to_know_python/dictionaries.html" rel="noreferrer">dictionaries</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload