jsonsum is an algorithm for hashing data structures in a streamable manner. It also normalizes string and number encodings.
Each type is represented by a token and a value and hashed in some way:
bool
/null
: Append the respective token t
/f
/n
to the hash for true
/false
/null
.string
: Append the string token s
followed by the hash of the string content to the hash.object
: For each key-value pair, create a separate hash consisting of the key and value, then xor all those hashes together. This allows the keys to be in arbitrary order without changing the hash. Append the object token o
followed by the xored hash to the hash.array
: Append the array start token [
, followed by all elements, followed by the array end token ]
to the hash.number
: Append the number token i
, followed by the normalized number to the hash. To normalize the number, take transform it into scientific notation and shift all non-zero digits left of the decimal point. Then encode the digits as ASCII-encoded decimal, preceded by a minus sign if negative, followed by e
and the exponent.language | streaming support |
---|---|
Go | ? |
Kotlin | ? |
Python | no |