I am using tSQLt to test stored procedures which output JSON string results. The problem I have is that the key/value pairs in JSON are not always the same order. For example, JSON1: {"A":1, "B":2} and JSON2: {"B":2, "A":1}
tSQLt.AssertEqualsString will fail when compares JSON1 with JSON2. I expects the test to be passed if only the order is different. Any help will be appreciated.
Thanks in advance!
There's currently no direct way to compare JSON in tSQLt.
However, one way you could deal with that is by splitting the JSON into a key/value pair table. You can for example use OPENJSON for that.
Once the values are in rows, you can use tSQLt.AssertEqualsTable to compare the expected result to the actual result.