1

I want to compare two json responses.I need a way to compare the reponses by not only ignoring the order of child attributes but also the ordering of elements inside json array. For ex:

target response:

{
     name:abc,
     category:bbb
     place:aaa,
     
     arrayList:[
           {
               id:1,
               description:blah blah,
               count:3
           },
           {
               id:2,
               count:4,
               description:blah blah
           }
      ]
}

source response

{
     name:abc,
     place:aaa,
     category:ccc
     arrayList:[
           {
               id:2,
               description:blah blah,
               count:3
           },
           {
               id:1,
               count:3,
               
           }

      ]
}

When I compare above two response i Should get a differenceList which has following differences

differenceList:[
     {  result: mismatch,
        targetPath: .category,
        sourcePath: .category,
        target: bbb,
        source: cccc
     },
     {  result: attribute not found in source response,
        targetpath: .arrayList[0].description,
        target: blah blah,
        source: null
     },
     {  result: Mismatch,
        targetpath: .arrayList[1].count,
        sourcepath: .arrayList[0].count,
        target: 4,
        source: 3
     }
]

tried using json comparator it doesnt seem to work. Need a java code for this

SasukeUchiha
  • 31
  • 1
  • 3
  • 2
    Does this answer your question? [How to compare JSON documents and return the differences with Jackson or Gson?](https://stackoverflow.com/questions/50967015/how-to-compare-json-documents-and-return-the-differences-with-jackson-or-gson) – Mark Jun 17 '21 at 03:37
  • It would've worked if dont want to ignore the ordering of two jsonArrays – SasukeUchiha Jun 17 '21 at 04:02

0 Answers0