0

I have two large nested json objects which I need to compare for equality.

I followed the following steps but failed.

  1. I converted the json objects into treemaps and json arrays into hashsets and finally returned a treemap for each.

  2. I used equals method of map to compare for equality.

  3. Though both the maps are sorted(treemaps) and exactly equal in key,value pairs,the comparision is resulting in not equal Can anyone suggest a good solution for this and the reason why the case is failing?

3
  • 1
    Can you show some code? Which library are you using? Commented Jun 21, 2016 at 11:03
  • can you provide a sample of json array let me know how nested is it? Commented Jun 21, 2016 at 11:03
  • Thanks to all for your response. I solved it by converting the final thing to String and comparing both the strings. As both are in sorted order it worked. Commented Sep 14, 2016 at 13:41

2 Answers 2

2

See this answer here: Compare two JSON objects in Java

Covers the same thing. There's a number of ways, but I suggestion Jackson: https://github.com/FasterXML/jackson

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to all for your response. I solved it by converting the final thing to String and comparing both the strings. As both are in sorted order it worked.
1

To Check instantly,

try http://jsondiff.com/

For programmatic approach

provide a sample of your JSON Data and code.

2 Comments

Thanks to all for your response. I solved it by converting the final thing to String and comparing both the strings. As both are in sorted order it worked.
@PriyaMounica , cheers , It is always best when you solve it on your own!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.