0

I want to exclude certain JSON attributes when comparing two JSON files using skyscreamer.

Test file1:

 {
   "Name":"test1",
   "addressList":[
      {
         "street":"123 fake street",
         "postalcode":"33344"
      },
      {
         "street":"99 street avn",
         "postalcode":"23434"
      },
      {
         "street":"900 street city",
         "postalcode":"45100"
      }
   ]
}

Test file2:

 {
   "Name":"test1",
   "addressList":[
      {
         "street":"123 fake street",
         "postalcode":"33344"
      },
      {
         "street":"88 abc street",
         "postalcode":"23434"
      },
      {
         "street":"900 street city",
         "postalcode":"45100"
      }
   ]
}

how to compare above JSON files by excluding addressList.street attribute?

vkt
  • 1,401
  • 2
  • 20
  • 46

1 Answers1

2

we can use the CustomComparator and write an own custom comparator based on needs

 org.skyscreamer.jsonassert.Customization
 org.skyscreamer.jsonassert.comparator.CustomComparator

example:

compareJSON(expected, actual,  new CustomComparator(JSONCompareMode,new Customization(addressList.street,(o1, o2) -> true)))
vkt
  • 1,401
  • 2
  • 20
  • 46