3 ms·
It is my understanding that the JSON encoding of objects is not specified canonically because the order of keys can be arbitrary. That is, JSON.stringify() is f
by nhaehnle 12y ago
It is my understanding that the JSON encoding of objects is not specified canonically because the order of keys can be arbitrary. That is, JSON.stringify() is free to return different strings for the same JSON object.
Is my understanding correct? If it is, that would totally break your suggestion.
- drostie 12y agoYou are correct, but if you control the environment enough to be doing this at all, then you control the environment enough to get the serialization consistent: either by having ordered dictionaries in the language a la Python and PHP, or implementing your own, or by sorting the keys lexicographically a la bencode. That is, `diff(sorted_json_stringify(json_parse(p)))` will be adequate if `diff(p)` is not.