Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would split this into two problems.</p> <ol> <li>How do you get the same serialized string in both JavaScript and Python?</li> <li>Which byte array hash function should you use? It must be an established algorithm with identical implementations in both JavaScript and Python.</li> </ol> <p>Use (1) to get two strings, then UTF8 encode, then use (2) to get hashes.</p> <p>Since (2) is straightforward, I'll only address (1).</p> <p>There are multiple facets to the problem of making sure the two JSON strings you generate are identical.</p> <ul> <li>You'll want to used unformatted JSON (no extraneous spaces, tabs, or newlines).</li> <li>null values must be treated identically. Some serializers will by default throw away a dictionary key-value pair if the value is null.</li> <li>Ordering of key-value pairs within a dictionary must be consistent.</li> <li>JSON number serialization should be consistent. For example, you can't have integer one serialize as <code>1</code> on one side and <code>1.0</code> on the other. (This probably won't be as big of an issue however.)</li> <li>The string encoding should be the same for both. JSON allows serialization to Unicode text, only mandating that <code>"</code> and <code>\</code> be backslash-escaped in JSON strings. Most serializers do more than necessary, however, and reduce almost all Unicode characters to the <code>\uXXXX</code> equivalent. See <a href="http://json.org/" rel="nofollow">json.org</a> for the details on JSON string encoding. One way to remove all ambiguity is to only escape when absolutely necessary.</li> </ul> <p>You'll want to make sure all of these are matched between JavaScript and Python. Most JSON serialization libraries I've used provide configuration hooks for all of the things I mention in the list above. Unfortunately, I'm not very familiar with the JavaScript or Python libraries.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload