title: Trying to sort items from my json in Javascript
body: <p>I have a JSON string that I parse to a JSON Object with the json2.js library.</p>
  
  <pre><code>var parsed = JSON.parse(jsonstring);
  </code></pre>
  
  <p>Afterwards I do some magic to show that data to the user. The contained data are several messages. In all browsers they are sorted in the correct order. However in IE9 the order is reversed. From old messages to new messages instead of the new messages first.</p>
  
  <p>I read that the order of the parsing result is not fixed and depends on the JavaScript version. So I tried to sort the items the way I want, but it's not working.</p>
  
  <p>I currently do:</p>
  
  <pre><code>var parsed = JSON.parse(feeds);
  parsed = sortJSON(parsed, "created");
  
  function sortJSON(data, key) {
       return data.sort(function(a, b) {
              var x = a[key]; var y = b[key];
              return ((x &lt; y) ? -1 : ((x &gt; y) ? 1 : 0));
          });
  }
  </code></pre>
  
  <p>But I get the following error in the console:</p>
  
  <blockquote>
    <p>Object doesn't support property or method 'sort'</p>
  </blockquote>
  
  <p>So my guess is that my sorting method isn't correct because of the structure of the JSON object. So the question is '<strong>What do I need to alter in my sort method so that it works?</strong></p>
  
  <p>Structure of my json string:</p>
  
  <pre><code> {"&lt;ID&gt;":{"text":"...","user":"...","created":"&lt;date&gt;",
   "subject":"","url":"...","img_class":".."},
  
   "&lt;ID&gt;":{"text":"...","user":"...","created":"&lt;date&gt;","subject":"",
   "url":"...","img_class":"..."}, &lt;MORE MESSAGES&gt; 
   }
  </code></pre>