esandorfi commited on
Commit
c4757db
·
unverified ·
1 Parent(s): 0bbea57

Add stable_hash function for JSON objects

Browse files
Files changed (1) hide show
  1. label_hash.py +10 -0
label_hash.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ import json
5
+ from typing import Any
6
+
7
+
8
+ def stable_hash(obj: Any) -> str:
9
+ canonical = json.dumps(obj, ensure_ascii=False, separators=(",", ":"), sort_keys=True)
10
+ return hashlib.sha256(canonical.encode("utf-8")).hexdigest()[:16]