4 ms·
Yes, but there are lots of ways to get different encodings (and therefore hashes) for the same data: whitespace, JSON object key order, and the different ways o
by skybrian 2y ago
Yes, but there are lots of ways to get different encodings (and therefore hashes) for the same data: whitespace, JSON object key order, and the different ways of escaping characters.
If you want a unique hash (like, for a hash table lookup) then you'll need to sort the keys of every object and use a particular implementation of JSON.stringify.
(Also, what do you mean by "you don't even need any separator?")
- magicalhippo 2y agoXML has a complex solution for this, canonicalization[1], to enable signed XMLs[2]. Seems some folks are trying the same with JSON[3]. [1]: https://en.wikipedia.org/wiki/Canonical_XML https://en.wikipedia.org/wiki/Canonical_XML [2]: https://en.wikipedia.org/wiki/XML_Signature https://en.wikipedia.org/wiki/XML_Signature [3]: https://www.rfc-editor.org/rfc/rfc8785 https://www.rfc-editor.org/rfc/rfc8785
- justincormack 2y agoThere are a few canonical json specs but they are different and in my experience the implementations are not correct.