0

I have two object, one Object A is from the existing production, and another Object B is from our new pipeline. Eventually they both will be serialized into JOSN. Now, I want to compare if these two pipeline generate the same results, which means that if these two object/JSON carry the same set of data.

NOTE THAT, the same means, they have the same schema, and carry the same SET of data. For example,

Object A has

{"person" : [{"name": "alice"}, {"name": "bob"}, {"name" : "mike"}]}, 

and

Object B has

{"person" : [{"name": "bob"}, {"name": "alice"}, {"name" : "mike"}]}. 

This will cause difference if you run JSONDiss something, but in my case, they should be considered as same even if the sequence of key/value pair is difference. The structure of the Object/JSON could be more complex but the idea is that, in each bag/sub-bags, they should contains same set of data.

For my case, the goal is not just find if they are "same" or not, but find what is the difference? for example, Object 3 has a key/value pair called "name" : "Tom" that object 1 does not have. I always and only need to compare two objects.

I am wondering that is there any existing library for doing that ? or is there any suggestion for doing that ?

13
  • Why are they considered the same? Commented Feb 3, 2015 at 19:51
  • 1
    @MattBall because collections inside the object are considered as sets, as stated in the question. Commented Feb 3, 2015 at 19:52
  • Have you tried ordering both arrays then compare the two? Commented Feb 3, 2015 at 19:54
  • 1
    Then you must use an external comparator. docs.oracle.com/javase/8/docs/api/java/util/Comparator.html Commented Feb 3, 2015 at 19:59
  • 2
    Parse the JSON into a POJO of some sort which uses the semantics you want. Commented Feb 3, 2015 at 20:01

1 Answer 1

0

I know this is a bit old ... (saw this after)

Here is an answer that should work: Compare JSON with nested arrays and jsons (Array order does not matter)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.