News for hackers. Stuff that matters.
Re:Show HN: JSON.equals in Java to compare two JSON's by jermo on Monday December 10, 2018 @08:03AM (#18647565)
Thought I'd share something I discovered about Json comparison. This simple line also works:

  return jsonObject1.toMap().equals(jsonObject2.equals);
because JsonObject uses HashMap internally which supports equals(). The downside is it would be slower because toMap() creates a copy.

Btw, downloaded java-commons as Maven dependency from JitPack: https://jitpack.io/#blobcity/java-commons

Re:Show HN: JSON.equals in Java to compare two JSON's by sanketsarang on Monday December 10, 2018 @09:05AM (#18647936)
Yes this also works. We were using this for a while until we landed up with very large JSON's. .toMap() is very expensive and takes significantly longer to execute on large JSON's.
Re:Show HN: JSON.equals in Java to compare two JSON's by mscasts on Monday December 10, 2018 @03:37AM (#18646226)
Can't one just simply check if the strings are equal?
Re:Show HN: JSON.equals in Java to compare two JSON's by sanketsarang on Monday December 10, 2018 @03:42AM (#18646246)
No string compare does not work, as the order of elements may not be the same so the strings may not be the same. The utility will report both JSON's as equal even if order of elements is different.
Re:Show HN: JSON.equals in Java to compare two JSON's by mscasts on Monday December 10, 2018 @05:23AM (#18646731)
Ok cool, thanks for the explanation!