title: The .json printed data doesn't respect the dictionary order in Python
body: <p>I am analyzing some real-time captured data in order to parse some TLS Client Hello information.
  After capturing and analyzing the data, I print out the information in an <code>output.txt</code> file as a <code>.json</code> format by using a dictionary in python.</p>
  <p><strong>My question is</strong> about the <code>.json</code> output in the <code>output.txt</code> file. The data is not being printed in order, which means it doesn't respect the order of the data in the dictionary (<code>output_dictionary.py</code>).</p>
  <p>The dictionary that I am using for the <code>.json</code> output:</p>
  <pre><code>output_dictionary.py
  
  HANDSHAKE = {
      &quot;Client_Hello&quot; : {
          'Length': 'unknown',
          'Version': 'unknown', 
          'Random': 'unknown', 
          'Session ID': 'unknown', 
          'Session ID Length': 'unknown', 
          'Cipher Suites Length': 'unknown',
          'Cipher Suites': 'unknown', 
          'Compression Method': 'unknown'
          }
      }
  </code></pre>
  <p>The function that fills the dictionary in order to print it as a <code>.json</code> with           <code>json_read(&quot;output.txt&quot;)</code> call:</p>
  <pre><code>def parse_client_hello(handshake):
      if isinstance(handshake.data, dpkt.ssl.TLSClientHello):
          client = dpkt.ssl.TLSClientHello(str(handshake.data))
          **HANDSHAKE[&quot;Client_Hello&quot;]['Length'] = len(client)**
          **HANDSHAKE[&quot;Client_Hello&quot;]['Version'] = tls_dictionary('tls_version',client.version)**
          
          **HANDSHAKE[&quot;Client_Hello&quot;]['Random'] = hexlify(client.random)**
          
          session_id, pointer = parse(client.data, 1)
          **HANDSHAKE[&quot;Client_Hello&quot;]['Session ID'] = hexlify(session_id)**
          **HANDSHAKE[&quot;Client_Hello&quot;]['Session ID Length'] = len(session_id)**
          
          ciphersuites, pointer1 = parse(client.data[pointer:], 2)
          ciphersuites, pretty_cipher_suites = parse_ciphers_compressions(ciphersuites, 'cipher_suites')
          **HANDSHAKE[&quot;Client_Hello&quot;]['Cipher Suites Length'] = len(ciphersuites)**
          **HANDSHAKE[&quot;Client_Hello&quot;]['Cipher Suites'] = pretty_cipher_suites**
          
          pointer += pointer1 
          compression_methods, pointer1 = parse(client.data[pointer:], 1)
          compression_methods, pretty_compressions = parse_ciphers_compressions(compression_methods,
              'compression_methods')
          **HANDSHAKE[&quot;Client_Hello&quot;]['Compression Method'] = pretty_compressions**
  
          json_read(&quot;output.txt&quot;)
  </code></pre>
  <p>The <code>json.read</code> function that converts the dictionary into a <code>.json</code> format:</p>
  <pre><code>def json_read(filename):
      with open(filename, &quot;a&quot;) as f:
          json.dump(HANDSHAKE, f, indent = 4)
      
  </code></pre>
  <p>How the data is printed in the <code>ouput.txt</code> file as a <code>.json</code> format:</p>
  <pre><code>{
      &quot;Client_Hello&quot;: {
          &quot;Session ID Length&quot;: 32, 
          &quot;Length&quot;: 236, 
          &quot;Version&quot;: &quot;TLS 1.2&quot;, 
          &quot;Handshake Type&quot;: &quot;Client Hello : 1&quot;, 
          &quot;Compression Method&quot;: [
              &quot;null&quot;
          ], 
          &quot;Session ID&quot;: &quot;3eadfb1c6243f6aa70a880af598d52873e1fe049f15c3a7e2e6f4a3e4b58fc0e&quot;, 
          &quot;Random&quot;: &quot;502143b34cab4a59f947a8da76f58e66215bf709e85f71f7cbfa4ead8e99736b&quot;, 
          &quot;Cipher Suites Length&quot;: 15, 
          &quot;Cipher Suites&quot;: [
              &quot;TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256&quot;, 
              &quot;TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256&quot;, 
              &quot;TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256&quot;, 
              &quot;TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256&quot;, 
              &quot;TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384&quot;, 
              &quot;TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384&quot;, 
              &quot;TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA&quot;, 
              &quot;TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA&quot;, 
              &quot;TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA&quot;, 
              &quot;TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA&quot;, 
              &quot;TLS_RSA_WITH_AES_128_GCM_SHA256&quot;, 
              &quot;TLS_RSA_WITH_AES_256_GCM_SHA384&quot;, 
              &quot;TLS_RSA_WITH_AES_128_CBC_SHA&quot;, 
              &quot;TLS_RSA_WITH_AES_256_CBC_SHA&quot;, 
              &quot;TLS_RSA_WITH_3DES_EDE_CBC_SHA&quot;
          ]
      }
  }
  </code></pre>
  <p>The problem is that the <code>.json</code> printed data doesn't respect the dictionary order, which means first it should have printed the length,the version,the random..etc.
  Is there a way to fix this?</p>