Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:39:29+00:00 2026-06-14T14:39:29+00:00

I am currently getting JSON data from the discogs API (mp3 tag data) and

  • 0

I am currently getting JSON data from the discogs API (mp3 tag data) and wish to sort the results by the key’s value. In this case I am trying to get data for a Guns n Roses song and the output has 1988 as the first one while the data actually has a record from 1987. How can I sort this data so that I can get to the sorted data by year (olderst to newest). The code below sorts by either key or value but thats not what I intended to get. Please help.

import json
import urllib2
request = urllib2.Request('http://api.discogs.com/database/search?sort=year&sort_order=asc&artist=%22Guns+N%27+Roses%22&track=%22Sweet+Child+O%27+Mine%22&format_exact=Album&type=master')
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 json_object['results']:
    try:
        from operator import itemgetter
        for k, v in sorted(row.items(), key=itemgetter(0)):
            print k, v
    except KeyError: 
        pass
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:39:30+00:00Added an answer on June 14, 2026 at 2:39 pm

    You could use list-comprehension and sorted() function for this:

    # filter  json_object['results']  first, as some of the items are missing the key 'year'
    
    In [33]: results = [x for x in json_object['results'] if 'year' in x]
    
    In [34]: sorted(results, key=lambda x: x['year'])
    

    or :

    In [79]: from operator import itemgetter
    
    In [80]: sorted(results, key=itemgetter('year'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently getting 2 arrays from the following get statement. $.getJSON(http://domain.com?callback=?, function(data){ $(#results).html(JSON.stringify(data)); I'm
I am currently having trouble getting a value from an AsyncTask that gets data
I am getting json data from my server to show them as a table.
Writing an iPhone app, and I'm getting my data from a REST API that
I am doing this faq section by getting content from json files, which I
i have a short code of getting json data from another domain, im a
Currently I am getting data from a mysql database using jquery, but I would
I'm currently puling data from an external XML file and converting it to JSON
I am currently getting the following data back from the server: { d: [
I am brand new to actually using an API, getting the JSON data and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.