title: How to custom-sort a list of dict to use in json.dumps
body: <p>I have a list similar to</p>
  
  <pre><code>allsites = [
      {
          'A5': 'G', 
          'A10': 'G', 
          'site': 'example1.com', 
          'A1': 'G'
      }, 
      {
          'A5': 'R', 
          'A10': 'Y',
          'site': 'example2.com', 
          'A1': 'G'
      }
  ]
  </code></pre>
  
  <p>Which I use in a <code>json.dumps</code>:</p>
  
  <pre><code>data = { 'Author':"joe", 'data':allsites }
  print json.dumps(data,sort_keys=True,indent=4, separators=(',', ': '))
  </code></pre>
  
  <p>This outputs the following JSON:</p>
  
  <pre><code>{
      "Author": "joe",
      "data": [
          {
              "A1": "G",
              "A10": "G",
              "A5": "G",
              "site": "example1.com"
          },
          {
              "A1": "G",
      (...)
  </code></pre>
  
  <p>I would like the "data" section of this JSON string to be sorted via a custom key ("alphabet"), in the case above this would be <code>site, A1, A5, A10</code> and actually look like:</p>
  
  <pre><code>{
      "Author": "joe",
      "data": [
          {
              "site": "example1.com",
              "A1": "G",
              "A5": "G",
              "A10": "G"
          },
          {
              "site": "example2.com",
              "A1": "G",
      (...)
  </code></pre>
  
  <p>I read about custom sorting in the <a href="https://wiki.python.org/moin/HowTo/Sorting/" rel="noreferrer">Sorting FAQ</a> but it just gives a way to override the comparison function, not to mention that I do not know how to insert this into my code.</p>
  
  <p>How to do that?</p>