title: JSON dump order in Python
body: <p>I am attempting to write to a JSON using a specific format.  I have attempted different methods of making the json.dump command to write to the file how the data is presented in the variables.  Any suggestions as attempted OrderDict and Sort-Keys, which was recommended previously and online.</p>
  <p><strong>01/07/2020</strong> - Here is the code for the order and the creation of the JSON file.</p>
  <pre><code>    data =[]
      subData=[]
      subData=media_add()
      data.append(OrderedDict(
          {
              &quot;values&quot;: [ {
                  &quot;CaseID&quot;: case_id,
                  &quot;CaseMetadata&quot;: [
                      {
                          &quot;CaseID&quot;:case_id,
                          &quot;PropertyName&quot;:case_name,
                          &quot;PropertyValue&quot;:case_value
                      }
                  ],
                  &quot;CaseNumber&quot;: case_num,
                  &quot;ContactEmail&quot;: contact_email,
                  &quot;ContactName&quot;: contact_name,
                  &quot;ContactOrganization&quot;: contact_org,
                  &quot;ContactPhone&quot;: contact_phone,
                  &quot;ContactTitle&quot;: contact_title,
                  &quot;Media&quot;: subData,
                  
                  &quot;TotalMediaFiles&quot;: len(final_results),
                  &quot;TotalPrecategorized&quot;: 0,
                  
                  &quot;SeizureDate&quot;: autData[3][1],
                  &quot;SourceApplicationName&quot;: &quot;Autopsy&quot;,
                  &quot;SourceApplicationVersion&quot;: autData[5][1]
                  }]}))
  
  
      # Serializing json  
      json_object = json.dumps(data, indent=5)
  
      # Writing to json file
  
      filename= (case_name_fn + &quot; &quot; + date_fn + &quot;.&quot; + time_fn + &quot;.json&quot;)
  
  
      with open(filename, &quot;w&quot;) as outfile: 
          json.dump(data, outfile, sort_keys=True, indent = 4, ensure_ascii = False)
  </code></pre>
  <p><strong>Update 04/09/2020</strong>
  Good Afternoon, due to the specific requirements, the Python Code needs to be written in Python 2.7. I have attempted to redo the above work in 2.7 instead of 3.6 like the original code however I cannot get the dump to stay in the order written in the code. I have re-attempted to use OrderedDict but this has failed.</p>
  <p>Is there another way to create a structed JSON file without using json.dump method.</p>