Compare 2 API's json responses coming in different Order
Hi Team,
I am running 2 API's. Need to compare the responses and based on the result we need to make the test as pass or fail. Main problem is in every run blocks are coming in random order. Please how to do automate?
API 1 Response:
{
"status": "success",
"type": [
{
"a": "1",
"b": "2"
},
{
"a": "11",
"b": "22"
},
{
"a": "111",
"b": "222"
}
}
API 2 Response:
{
"status": "success",
"type": [
{
"a": "1",
"b": "2"
},
{
"a": "111",
"b": "222"
},
{
"a": "11",
"b": "22"
}
}
Answers
-
Sorting the JSON arrays prior to comparing them is likely what you want. There is a way to do this that would not involve any scripting. For each response, chain an XML Converter to convert the JSON to XML. Next, chain an XML Data Bank to store each resulting XML document in a Data Bank column. To compare the responses, use a Diff tool with Diff Mode set to XML with "Ignore element order" enabled. This option effectively sorts the XML tags prior to comparing them. You can select or reference data source columns on the Diff tool's Input and Regression Control tabs.
0