Hash a stable representation of data
Two dictionaries can describe the same JSON object even if their insertion orders differ. Hashing a casual string representation would treat them as different. Canonical encoding fixes key order, whitespace and character encoding before hashing. Reject NaN and infinity because they are not JSON numbers, and use a cryptographic digest rather than Python's process-dependent hash.
import json
print(json.dumps({"b":2,"a":1},
sort_keys=True))Think before coding
The digest identifies the chosen serialized representation. Key sorting removes insertion-order differences and fixed separators remove formatting choices. This is a local canonicalization policy, not a claim to implement every external canonical JSON standard. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write content_id(value). Encode a JSON-compatible value with sorted keys, separators (",", ":"), ensure_ascii=False, allow_nan=False; UTF-8 encode it and return its SHA-256 hexadecimal digest.
The explanation opens here once every check passes.