Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Compare 2 API's json responses coming in different Order

snrlrao
snrlrao Posts: 1

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

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    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.