Note that there are some explanatory texts on larger screens.

plurals
  1. POpython JSON sorting by key's value and then showing filtered data
    primarykey
    data
    text
    <p>I am trying to sort JSON data by the keys's value (year) and then <strong>trying to only display items that are in format 'DVD'</strong>, I tried many methods but am not alble to arrive at a clean solution. Can you please help me on how I can solve this? I am new to python, kindly pardon if this is too simple to ask here.</p> <p>JSON:</p> <pre><code>{ "pagination": { "per_page": 50, "pages": 1, "page": 1, "urls": {}, "items": 8 }, "results": [{ "style": ["RnB/Swing", "Ballad"], "thumb": "http://api.discogs.com/image/R-90-217365-1270055830.jpeg", "title": "Britney Spears - Oops!...I Did It Again", "country": "US", "format": ["CD", "Album"], "uri": "/Britney-Spears-OopsI-Did-It-Again/master/27443", "label": ["Jive"], "catno": "01241-41704-2", "year": "2000", "genre": ["Pop"], "resource_url": "http://api.discogs.com/masters/27443", "type": "master", "id": 27443 }, { "thumb": "http://api.discogs.com/image/R-90-2029929-1259535792.jpeg", "title": "Britney Spears - The Singles Collection", "country": "UK", "format": ["CD", "Compilation"], "uri": "/Britney-Spears-The-Singles-Collection/master/203074", "label": ["Jive"], "catno": "88697 623422", "year": "2009", "genre": ["Pop"], "resource_url": "http://api.discogs.com/masters/203074", "type": "master", "id": 203074 }, { "style": ["RnB/Swing"], "thumb": "http://api.discogs.com/image/R-90-1895804-1250792689.jpeg", "title": "Britney Spears - Greatest Hits: My Prerogative", "country": "US", "format": ["DVD", "Compilation", "NTSC"], "uri": "/Britney-Spears-Greatest-Hits-My-Prerogative/master/270902", "label": ["Jive", "Zomba Video"], "catno": "82876-65443-9A", "year": "2004", "genre": ["Electronic", "Pop"], "resource_url": "http://api.discogs.com/masters/270902", "type": "master", "id": 270902 }, { "style": ["RnB/Swing", "Ballad"], "thumb": "http://api.discogs.com/image/R-90-2421214-1283141143.jpeg", "format": ["DVD", "DVD-Video", "NTSC", "Multichannel"], "country": "US", "barcode": ["0 1241-41784-9 7"], "uri": "/Britney-Spears-Live-From-Las-Vegas/master/271031", "label": ["Jive"], "catno": "01241-41784-9", "year": "2002", "genre": ["Electronic", "Hip Hop", "Pop"], "title": "Britney Spears - Live From Las Vegas", "resource_url": "http://api.discogs.com/masters/271031", "type": "master", "id": 271031 }, { "style": ["Europop"], "thumb": "http://api.discogs.com/image/R-90-2410806-1283122933.jpeg", "format": ["DVD", "DVD-Video", "NTSC"], "country": "US", "barcode": ["0 1241-41704-9 1"], "uri": "/Britney-Spears-Live-And-More/master/270904", "label": ["Jive"], "catno": "01241-41704-9", "year": "2000", "genre": ["Pop"], "title": "Britney Spears - Live And More!", "resource_url": "http://api.discogs.com/masters/270904", "type": "master", "id": 270904 }] } </code></pre> <p>PYTHON:</p> <pre><code>url1 = "http://api.discogs.com/database/search?sort=year&amp;sort_order=" url2 = "asc&amp;artist=%22"+artist+"%22&amp;track=" url3 = "%22"+song+"%22&amp;format_exact=Album&amp;type=master" url = url1 + url2 + url3 print url request = urllib2.Request(url) request.add_header('User-Agent','Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)') request.add_header('Content-Type','application/json') response = urllib2.urlopen(request) json_raw = response.readlines() json_object = json.loads(json_raw[0]) for row in sorted(json_object['results']): #stuck here to sort on key's value... print '-----------------------------start------------------------------------------' print row['format'] print row['id'] print '-----------------------------end--------------------------------------------' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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