title: how to keep order of sorted dictionary passed to jsonify() function?
body: <p>I'm trying to pass sorted dictionary to jsonify() function and then use it from within JS code to take out values. What I see there is that even though I pass correct values, they are reordered by jsonify for some reason.</p>
  
  <pre><code>
  json_data = {
      "11": {
          "j_id": "out",
      },
      "aa": {
          "j_id": "in",
      },
      "bb": {
          "j_id": "out",
      },
  }
  
  jkeys=json_data.keys()
  sorted_json = sorted(jkeys, key=lambda x: json_data[x]['j_id'], reverse=False)
  
  new_sorted=OrderedDict()
  for rec in sorted_json:
      new_sorted[rec]=json_data[rec]
  
  print('sort dict: {}'.format(new_sorted))
  </code></pre>
  
  <p>The output is correct and I can see proper values which in my case should be: aa, 11, bb</p>
  
  <pre><code>&gt;&gt;&gt; from collections import OrderedDict
  &gt;&gt;&gt;
  &gt;&gt;&gt; json_data = {
  ...     "11": {
  ...         "j_id": "out",
  ...     },
  ...     "aa": {
  ...         "j_id": "in",
  ...     },
  ...     "bb": {
  ...         "j_id": "out",
  ...     },
  ... }
  &gt;&gt;&gt;
  &gt;&gt;&gt; jkeys=json_data.keys()
  &gt;&gt;&gt; sorted_json = sorted(jkeys, key=lambda x: json_data[x]['j_id'], reverse=False)
  &gt;&gt;&gt;
  &gt;&gt;&gt; new_sorted=OrderedDict()
  &gt;&gt;&gt; for rec in sorted_json:
  ...     new_sorted[rec]=json_data[rec]
  ...
  &gt;&gt;&gt; print('sort dict: {}'.format(new_sorted))
  sort dict: OrderedDict([('aa', {'j_id': 'in'}), ('11', {'j_id': 'out'}), ('bb', {'j_id': 'out'})])
  </code></pre>
  
  <p>Unfortunately, when I pass this to jsonify() function and then for example console.log() output of flask data, the orderd becomes like that: 11, aa, bb. Additionally to that, I've done some research and found <a href="https://stackoverflow.com/questions/43263356/prevent-flask-jsonify-from-sorting-the-data">this</a> stackoverflow answer, leading to some <a href="http://flask.pocoo.org/docs/0.12/config/#config" rel="noreferrer">good documentation notes</a> which clearly states that setting <em>JSON_SORT_KEYS</em> to <em>False</em> is not recommended way. Then I checked <a href="https://github.com/pallets/flask/issues/974" rel="noreferrer">this github issue</a> and it seems that problem is not fully resolved in flask.</p>
  
  <p>What would be the best way to fix it in my case?</p>