Diff JSON comparision by ignoring the order.
Hi Team
is there any way to ignore the order while comparing the json.
problem statement :
Posting an array of data from excel
while getting the response of same data, i am getting the order mismatch.
for example, 0th position goes to 1st position and vice versa.
Thanks
Udaya
Comments
-
Adding additional information:
LeftHandside or actual:
[
{
"product" : "One"
"color" : "red",
"valu" : "#f00"
},
{
"product" : "Two"
"color" : "green",
"valu" : "#0f0"
},
{
"product" : "Three"
"color" : "blue",
"valu" : "#00f"
},
{
"product" : "Four"
"color" : "cyan",
"valu" : "#0ff"
}
]RightHandside or expected:
[
{
"product" : "Four"
"color" : "cyan",
"valu" : "#0ff"
},
{
"product" : "Two"
"color" : "green",
"valu" : "#0f0"
},
{
"product" : "Three"
"color" : "blue",
"valu" : "#00f"
},
{
"product" : "One"
"color" : "red",
"valu" : "#f00"
}
]There are only four products, But the order has changed.
0 -
JSON diffs require array elements to be in the same order, which is why you are seeing this behavior. One way to do this is to convert your JSON to XML using the XML Converter tool, and then use the XML Sort tool to sort the XML before performing an XML diff using the Diff tool. This will require you to use XML within your regression control, which you will need to get by identifying what the sorted XML will look like and then pasting that into your Diff tool.
1 -
Gotcha. Thanks..
0 -
Suggestion is not working.
I am able to use the XML convertor on my JSON response. On top of that i used the XML SORT, where as XML sort is not sorting my parsed response.0 -
The XML Sort tool is somewhat deprecated. It was originally used to sort XML prior to diffing as a means to ignore element order. However, this has been somewhat obsoleted by the fairly recent addition of the XMLUnit diff engine which has a "Ignore element order" option. So, consider not using the XML Sort tool to simplify your test setup.
1 -
Thanks Ben its working!!
0