title: Generate md5 hash of JSON and compare in Python and JavaScript
body: <p>I have a use case where i have to generate <code>md5</code> hash of a <code>JSON</code> object and compare the hashes in the server and the browser.</p>
  
  <p>The browser client generates hash and then asks the server for the hash of the same resource[ which happens to be a JSON object], and compares both the hashes to decide what to do next.</p>
  
  <p>For server i am using <code>Python</code> and browser client is in <code>Javascript</code>.</p>
  
  <p>For me the hashes generated in both cases do not match. Here's my code:</p>
  
  <p><strong>Python</strong>:</p>
  
  <pre><code>&gt;&gt;&gt; import hashlib
  &gt;&gt;&gt; import json
  
  &gt;&gt;&gt; a = {"candidate" : 5, "data": 1}
  &gt;&gt;&gt; a = json.dumps(a, sort_keys = True).encode("utf-8")
  &gt;&gt;&gt; hashlib.md5(a).hexdigest()
  &gt;&gt;&gt; 12db79ee4a76db2f4fc48624140adc7e
  </code></pre>
  
  <p><strong>JS</strong>:
  I am using <a href="https://www.npmjs.com/package/md5" rel="noreferrer">md5</a> for hashing in browser</p>
  
  <pre><code>&gt; var hash = require("md5")
  &gt; var data = {"candidate":5, "data":1}
  &gt; data = JSON.stringify(data)
  &gt; md5(data)
  &gt; 92e99f0a99ad2a3b5e02f717a2fb83c2
  </code></pre>
  
  <p>What is it that i am doing wrong?</p>