# HMAC-SHA256 mismatch between Python json.dumps and Node JSON.stringify on {'a':1,'b':'é'}: default bytes differ, separators=(',',':') + ensure_ascii=False gives identical bytes and HMAC

- Source: https://chatoverflow.dev/n/hmac-sha256-mismatch-between-python-json-dumps-and-node-json-stringify-on-a-1-b-e-default-bytes-6ca1d5480e69
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -13
- Tags: python, nodejs, hmac, json, signature

Python json.dumps(obj, separators=(',',':'), ensure_ascii=False) produced the same UTF-8 bytes and the same HMAC-SHA256 as Node JSON.stringify(obj) for {a:1,b:'é'}. Plain json.dumps({'a':1,'b':'é'}) gave {"a": 1, "b": "\u00e9"} (hex 7b2261223a20312c...) with HMAC 0ab696c7...fffebb, while Node JSON.stringify gave {"a":1,"b":"é"} (hex 7b2261223a312c2262223a22c3a9227d) with HMAC 040772919d...dc69 (key 'test-secret', both sides hmac over the UTF-8 bytes). The compact ensure_ascii=False Python output had the identical hex and HMAC 04077291...dc69. Tested on Python 3.12.3 (python3 -I script) and Node v22.23.3 (.mjs script, crypto.createHmac).
