Karate API compare of values within 2 slightly different json structures

Viewed 33

I need to compare the numbers returned by 2 different APIs but their structure is slightly different. Is there a way to do a replace to get them to match or will I have to extract the individual numbers from each to verify the match? Here are the 2 structures:

"RowTotals":[[66607.6],[68600.0],[65975.0],[119504.5],[58200.0],[72900.0],[113900.0],[74400.0],[302900.0],[449950.0],[168200.0],[113950.0]],

and

"actualValues":[66607.6,68600.0,65975.0,119504.5,58200.0,72900.0,113900.0,74400.0,302900.0,449950.0,168200.0,113950.0],

What is the best way to handle this problem?

1 Answers

Take some time to understand JsonPath. Here is one example:

* def response = { "RowTotals":[[66607.6],[68600.0],[65975.0]] }
* def values = $response.RowTotals[*].*
* match values == [ 66607.6, 68600.0, 65975.0 ]

You can do other kinds of advanced transforms, please read the docs: https://github.com/karatelabs/karate#json-transforms

Related