title: How can I preserve the order of an OrderedDict when converting it to JSON
body: <p>I am writing a a REST API in python3 using flask and I have struggled to find a way to return a dict as json while maintaining the order of the keys. I am using an OrderedDict because obviously the built in dictionary does not preserve order of elements.</p>
  
  <p>I have a method that looks like this:</p>
  
  <pre><code>@app.route('/foobar', methods=['GET'])
  def foobar()
      data = [OrderedDict([("a",1),
          ("b",2),
          ("c",3)])]
      return jsonify(data),200
  </code></pre>
  
  <p>And here is an example of the output I could get:</p>
  
  <pre><code>[{"b":2,"c":3,"a":1}]
  </code></pre>
  
  <p>This is what I want to get:</p>
  
  <pre><code>[{"a":1,"b":2,"c":3}]
  </code></pre>
  
  <p>How can I return JSON in the order that its defined in the ordered dict? </p>
  
  <p>Edit:
  This is not a duplicate because the linked post is only for a dictionary I need this to work for a list of dictionaries</p>