Need to know how to compare two json response one with json object and other with json array .
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2018
06:43 PM
10-29-2018
06:43 PM
Need to know how to compare two json response one with json object and other with json array .
Solved! Go to Solution.
6 REPLIES 6
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018
01:22 PM
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018
02:24 PM
10-30-2018
02:24 PM
Hi Radhika,
How would you normally do it if they both had single objects? However you normally would, you should be able to do the same thing but just get the first object out of the the list.
For example:
assert json1.'consumerProfile'.'consumerProfileIdentifier'.'profileID' == json2.'consumerProfile'.'consumerProfileIdentifier'[0].'profileID'
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018
02:58 PM
10-30-2018
02:58 PM
Can you help me how to do this for all objects if possible.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018
07:44 PM
10-30-2018
07:44 PM
can some one help me here
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018
12:46 PM
11-01-2018
12:46 PM
How about this:
log.info("start") def listA = [] def listB = [] def slurperA = new JsonSlurper().parseText(<json 1 text>) def slurperB = new JsonSlurper().parseText(<json 2 text>) slurperA.each { key, value -> loop(listA, key, value) } slurperB.each { key, value -> loop(listB, key, value) } log.info("matches: " + listA.intersect(listB)) log.info("mismatches A: " + listA.minus(listB)) log.info("mismatches B: " + listB.minus(listA)) log.info("done") def loop(list, key, value) { if(value.class == null) { if(value != null && !value.isEmpty()) { value.each { k, v -> loop(list, (key + '.' + k), v) } } else { //log.warn(key + ": empty") list.add((key)) } } else if(value.class == ArrayList) { value.each { loop(list, key, it) } } else { //log.info(key + " = " + value) list.add(key + " = " + value) } }
Will give you something like this:
Thu Nov 01 20:43:49 CET 2018:INFO:matches: [consumerProfile.consumerProfileIdentifier.profileID = 85750290, consumerProfile.consumerProfileIdentifier.type = UCPID,... Thu Nov 01 20:43:49 CET 2018:INFO:mismatches A: [_class = com.moneygram.coreservices.ProfileCacheService.web.model.ConsumerProfileCacheDocument, consumerProfile.auditEvent.agentID = 40307666,... Thu Nov 01 20:43:49 CET 2018:INFO:mismatches B: [consumerProfile.auditEvent.agentID, consumerProfile.auditEvent.sourceSystemUserID, consumerProfile.auditEvent.updateDate = 2018-10-30T11:34:35-05:00,...
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2018
07:55 PM
11-03-2018
07:55 PM
thaks this is awesome.
