Comparing nested json | Selenium Forum
R
Ritesh Posted on 10/09/2020

I want to find if Json1/Json2 present in actual json, can anyone help with. I tried using JsonAssert but it is not working.

JSON 1: {"Make":[{"TxnID":"204440678","Price1":234.0,"Price2":234.0,"Price3":234.0}],"device":""}

JSON 2 : {"Make":[{"TxnID":"204440678","Price1":234.0,"Price2":234.0,"Price3":234.0},{"TxnID":"204539778","Price1":100.0,"Price2":100.0,"Price3":2003.0}],"device":""}
 
JSON Actual: {"Make":[{"TxnID":"204440678","Price1":234.0,"Price2":234.0,"Price3":234.0},{"TxnID":"204667533","Price1":300.0,"Price2":300.0,"Price3":300.0},{"TxnID":"204670850","Price1":300.0,"Price2":300.0,"Price3":300.0},{"TxnID":"204539778","Price1":100.0,"Price2":100.0,"Price3":2003.0},{"TxnID":"204667407","Price1":253.0,"Price2":231.0,"Price3":242.0},{"TxnID":"204670691","Price1":100.0,"Price2":100.0,"Price3":2001.0},{"TxnID":"204669481","Price1":583.0,"Price2":561.0,"Price3":572.0},{"TxnID":"79221531","Price1":100.0,"Price2":100.0,"Price3":2002.0},{"TxnID":"204670792","Price1":583.0,"Price2":561.0,"Price3":572.0},{"TxnID":"204649121","Price1":2503.0,"Price2":2301.0,"Price3":2402.0},{"TxnID":"204671371","Price1":330.0,"Price2":330.0,"Price3":330.0},{"TxnID":"79235631","Price1":3000.0,"Price2":3000.0,"Price3":3000.0}],"requestId":"3B36BD58-55FB-4AAB-83E7-67377159261B","device":"","status":"success"}
 
Code-

JSONAssert.assertEquals(json1, jsonactual, JSONCompareMode.LENIENT);

Error:
Exception in thread "main" java.lang.AssertionError: Make[]: Expected 1 values but got 12
at org.skyscreamer.jsonassert.JSONAssert.assertEquals(JSONAssert.java:482)
at org.skyscreamer.jsonassert.JSONAssert.assertEquals(JSONAssert.java:464)
at quinstreet.jsoncompare.JSONCompareAssert.main(JSONCompareAssert.java:49)


A
Ashish Replied on 11/09/2020

You have to use rest assured tool for this

Selenium as a tool will not help in this


Related Posts