Behold, a way to deterministically hash JSON without canonicalization https://gist.github.com/DavidBuchanan314/e2d84c50cbd8e7c86eaa25f0c5b29a5c

This is probably broken, I look forward to someone who is good at maths telling me that I'm doing it wrong.

@retr0id One problem I can think of: how would this handle the difference in decimal/float number handling that can exist between languages?

· · Web · 2 · 0 · 0

@retr0id (This presumes that inter-language determinism is desirable; which seems like a reasonable assumption, given that if it's not, your language of choice likely has a language-specific deterministic hashing mechanism anyway, and you don't need to deal with JSON anything)

@joepie91 That is indeed an issue, but I don't think *anyone* has a good solution to it. For applications where it might matter, it's best to disallow floats entirely tbh.
Could perhaps be solved with sufficiently pedantic rules about how to transform the original JSON number string into serialized bytes. JSON itself is not guaranteed to be interoperable with numbers outside the range of a double-precision float, though
Sign in to participate in the conversation
Pixietown

Small server part of the pixie.town infrastructure. Registration is closed.