I want to get the same digest value when contents of two JSONs are equal. For example, I want the following two to generate the same digest value although spaces, newlines and the key order are different.
{
"key1": "value1",
"key2": "value2"
}
{"key2":"value2", "key1":"value1"}
About a year ago, I wrote my own Java implementation (nv-digest) which can be used like below.
// Compute SHA-1 of two JSONs.
// 'result1' and 'result2' will have the same value.
String json1 = "{ \"key1\":\"value1\", \"key2\":\"value2\" }";
String json2 = "{ \"key2\":\"value2\", \"key1\":\"value1\" }";
String result1 = Digest.getInstanceSHA1().updateJson(json1).digestAsString();
String result2 = Digest.getInstanceSHA1().updateJson(json2).digestAsString();
However, if there is a prevailing way to do the same thing, I want to use it. Could you recommend any library or existing specification?