Swetha Kumar
Swetha Kumar

Reputation: 1

How to list down all the differences while comparing two JSONs

Here is my code.

*  def aJson = [{foo1:2}, {bar1:2} , {foo2:null}, {bar2:a}]
*  def bJson = [{foo1:4}, {bar1:2} , {foo2:null}, {bar2:b}];
*  match aJson == bJson

The response is .. com.intuit.karate.exception.KarateException: Elimination.feature:25 - path: $[0], actual: {foo1=2}, expected: {foo1=4}, reason: [path: $[0], actual: {foo1=2}, expected: {foo1=4}, reason: all key-values did not match]

I want to list all the differences as:

com.intuit.karate.exception.KarateException: Elimination.feature:25 - path: $[0], actual: {foo1=2}, expected: {foo1=4}, reason: [path: $[0], actual: {foo1=2}, expected: {foo1=4}, reason: all key-values did not match]

actual :{foo1=2}, expected :{foo1=4}, actual :{bar2:a}, expected :{bar2:b}

Upvotes: 0

Views: 107

Answers (1)

Adrien
Adrien

Reputation: 1090

Karate version: 0.9.1
======================================================
elapsed:   0,27 | threads:   10 | thread time: 0,04 
features:     1 | ignored:    1 | efficiency: 0,01
scenarios:    1 | passed:     0 | failed: 1
======================================================
failed features:
examples.users.test: test.feature:7 - path: $[0], actual: {foo1=2}, expected: {foo1=4}, reason: [path: $[0].foo1, actual: 2, expected: 4, reason: not equal (Integer)]

This is the result for your code with version 0.9.1, which provided a bugfix for this. As far as I know, it won't be possible to have information about both foo1 and bar2 being wrong.

Upvotes: 1

Related Questions