Verify ComplexJsonResponses

To make Katalon better for web testing…

I would like Katalon to create Keyword WS.verifyComplexJsonResponsesAreEqual(json1, json2)
or sort of like:
def response = WS.sendRequest(findTestObject(‘api/req’, [ (‘env’) : GlobalVariable.BASE_ENV]))
def expectedResponse = “”"
{ “news”: {
{“created”: “today”, “title”: “abc” }.,
“created”: “tomorrow”, "title:“def”}
… etc… complex json object with arrays of objects…

WebUI.verifyComplexJsonResponsesAreEqual(response, expectedJSONReadInFromAFile)

It is very useful to compare json responses and get a diff when they are not equal.
These tests are very useful in smoke test scenarios.

I hope this can be completed as I believe many people will benefit from it tremedously.

Thank you

Philip novikov

1 Like

My previous solution is here:

The Test Case source code is here

My code utilizes the Java Diff Utilities library. It can process any format of text: XML, JSON, CSV, HTML, …

The output from this solution is something like this:

- original: `/Users/username/projectdir/Include/fixtures/doc1.xml`
- revised : `/Users/username/projectdir/Include/fixtures/doc2.xml`


- inserted rows: 0
- deleted rows : 0
- changed rows : 3
- equal rows:  : 5

|3|*<section>*|**<section id="main">**|
|4|<p>Hello, *John!<*/p>|<p>Hello, **Paul!<**/p>|
|5||**<p>Have a break!</p>**|

This output is formated in the “Markdown” format.
You would need a viewer for *.md file.
Katalon Studio does not support rendering Markdown files.
I would recommend to use Visual Studio Code with Markdown plugin.

With VSCode, you can preview any Markdown documents, like this

I have ever developed a more comprehensive solution for myself.

This enabled me to organize a mass of downloaded web resources (screenshot images, html, json, xml, etc) in a custom domain-specific database on the local file system. It can compare 2 sets of web resources (2 sets downloaded from a single host at different timing, or 2 sets downloaded from different hosts, such as the development environment and the productional environment). It can compile a diff report with rich meta data.

The following screenshot shows a sample image of the report.

1 Like

There is no point into diffing json files, IMHO (and with any other structured data files, e.g. xml)
Altough is doable as @kazurayam already shown, I will keep this method usage for files ‘not easy to parse’.

I will better use json schema validation at first, to check if the main structure of the response is fine, followed by a certain data validation (parse the json, iterate over it, compare with whatever input data)

Why am I saying this? Well, let’s take a look at the following example:
File A

	key1: value1,
	key2: value2

File B

	key2: value2,
	key1: value1

If you diff them you will get a failed test.
However, both have the same schema, and from the data point of view, both of them are valid.

It is nice for me to find the File A and the File B being different.

If I find my program genereted the File A at a time and the File B next, I would be surprised.

What happened to my product? Broken? I would like to check it.

may be nice for you but not for me, particularily with json.
objecs are not sorted, and depending on the serialization method used under the hood, with each call you may get a slightly different file.
i know plenty api’s working like this, e. g Jira api.
so using diff with json will only get false negative
you call this a defect? or lazy programing? it is not.
the code is optimized to use async processing, so this can occur particularily with large data
the data is valid, so the code is robust. if you use the data wrong, the issue is on the tester/consumer side

one more challenge for you, with json.
what if you have a paged endpoint?
good luck to diff such to validate the response

I’m well aware how JSON Schema helps us. But I would not choose the verification using JSON schema at first.


The reason is trivial. A web app in early stage of development tends to respond mal-formed (broken) JSON-like texts. For example,

	"key1": "value1"
	"key2": "value2"

JSON Schema validation doesn’t work with mal-formed JSON-like files. A text-diff tool can deal with any texts. So I would choose it first.

Comoon, @kazurayam
Are you able to distinguish between a json array and a json object?
i will expect more from your side …
The example provided by you is not valid, nor by schema, nor by data.
So it will fail from the schema validation at a minimum

Comoon, @bionel … you didn’t read my explanation.

as you didn’t read my explanations.
json is a structured data. make no sense to diff it.
you will get only fake validation even if the sample used for refference is malformed

Enough. I will quit this. Bye.

bye, and good luck with testing.
why to attempt to validate a malformed json? only you may know the answer.
if it is malformed, the AUT is already screwed. period!
so it is waste of time to proceed further with data validation

If it is written (and tested) by monkeys . Or, perhaps, by ChatGPT.
Are you aware that, you can check also with an API response the type of the data content received?
(which should be the previous check, prior to schema validation and further)
or should i go even further and say that, before any check, you should check the response code?

so you are suggesting that, the tester should spend time and effort to write voodoo ‘validation’ code because the developper of the AUT is lazy or dumb and is not using proper serialization / de-serialization libraries from the early beginning?
think twice…

i dont understand your point bionel.
There are many times I have visually validated a response from an API. It has 30 fields. I want to check when the API returns something different. as this could mean there is a new bug.
In my case, the order of the JSON always comes in the same. Kazarayems code seems to be very useful. I am excited to try. Kaz, do you use Visual studio code to program tests in Katalon? I would love to do this!

ofcourse you don’t.
otherwise you wouldn’t rise this topic.
looks like i am the only one on this comunity understanding data structures and how to properly handle it, from the early begining of the development to validation.
good luck with your approaches and have fun when you will have to deal with serious AUTs consuming really large datasets.
(30 fields is a joke)
so kindly mark kazu suggestion as a solution to close this topic

LE: don’t take this as a passive/aggressive answer, despite it looks like.
it is just an advice from my side.
you can ignore it.


We can not develop the codes (Test Case, Keyword) of a Katalon project in VSCode. We can execute Test Cases only inside Katalon Studio (or Katalon Runtime Engine). Katalon Test Cases never run inside VSCode.

However, VSCode is usefull to do various operations that Katalon Studio does not support. For example

  1. VSCode lets me open the Terminal UI. KS doesn’t. In the Terminal, I operate the git command. I operate the gradle command quite often.
  2. VSCode lets me open a *.html file as raw text and let me edit it.

Katalon Studio doesn’t let me open a *.html file as raw text. When I double-click a index.html file stored in the project somewhere, Katalon always open it inside the browser. Therefore in Katalon Studio, I am not able to edit a file of which name ends with .html. I am not joking.

  1. VSCode can render the preview of text files in Markdown format and in Asciidoc format. VSCode can render the diagrams created by the PlantUML language. I use these formats for authoring documentations.
  2. VSCode HAR Viewer lets me quickly look into a HTTP Archive file.
  3. Text editors for *.html, *.js, *css, *.json, *.xml … of VSCode are superb. Color themes, indentation, auto-formatting, code suggestions, spell-checking — all in VSCode are just comfortable. Katalon’s editor is (as you know) as dum as Notepad.

So I employ VSCode quite often to supplement Katalon Studio.

I have a dream that one day in the VSCode window, I will be able to develop the source code of my web app and my Katalon tests together as one united project.

1 Like

I have revised my previous work. Please check this again.

I have made a jar that contains a custom Keyword that does diff 2 texts and create a report in Markdown.

Possibly the following example is most relevant to @philippe.novikov

This gives you an output like this:

Just my 2cents, but I tend to agree with @bionel here. The solution to do a diff might be valid for some users in some use cases (e.g. static API responses), but if you are serious on verifying complex json responses, diffs are not the best solution.
Besides the points already mentioned, most of the time, API responses will have items like GUUID’s or dateTime stamps, which of course will always be different each time you generate it. Proper json deserialization (JsonSlurper e.g.) can then help to assert in a more robust way. Katalon does have some “Verification” code snippets, but this is all very basic in my opinion. I use a dedicated API testing tool to be more efficient on this and we use Katalon as more dedicated Front End testing tool.
I won’t name the other tool, we are at Katalon forum, but here is just a screen to show how an api JSON response can be visualized with quick click actions to do property content assertions & jsonPath matches (might help Katalon devs to see how current webservice tests can be improved).
These types of assertions need to be used in combo with the HTTP response code check, the schema validation, SLA reponse times checks etc. like Bionel mentioned. The assertion can also be expanded with more scripting, like in the use case where the sorting in the response is not always guaranteed.


My post is in no way any mean of invalidating anyone else his/her opinion. This is just my view from years of experience on API testing, so please don’t take any offense on this as it is not intended this way…

1 Like

Nobody should take it as an offense … I hope.
We are engineers here, with different points of view.
And we came from different fields.
As long as the topics are not taken personally, we are good :slight_smile:

Debates … well, will always be, and this is the purpose of the comunity.
To exchange experience and visions. And mistakes.


I would like to propose my solution to @bionel’s point. See the following

I will quote a relevant section from this article.

ex43 pretty print JSON then diff

Let me assume I have 2 JSON instances:





These 2 JSON instances are semantically identical.

If I apply take textual diff of the FileA and FileB, I will get the following diff report.

ex43 output1

This diff report is arguable. This report tells me that there are textual differences. However, if I do not like to be disturbed by the differences which are semantically insignificant, the above report is too noisy.

Now I would apply the methodology “ex42 pretty print JSON while ordering Map entities by keys”. I would convert the 2 input JSON and then take the diff.
The following report shows the result.

ex43 output2

The following Test Case creates these 2 diff reports.

import com.kazurayam.ks.TextsDiffer
import com.kazurayam.ks.JsonPrettyPrinter

// ex43 pretty print JSON then diff

String textA = """{
    "key1": "value1",
    "key2": "value2"
File fileA = new File("build/tmp/testOutput/ex43-fileA.json")
fileA.text = textA

String textB = """{
    "key2": "value2",
    "key1": "value1"
File fileB = new File("build/tmp/testOutput/ex43-fileB.json")
fileB.text = textB

// compare 2 JSON files as is
TextsDiffer differ = new TextsDiffer()
differ.diffFiles(fileA, fileB, new File("build/tmp/testOutput/"))

// convert 2 JSON texts (order Map entries by keys)
String ppA = JsonPrettyPrinter.orderMapEntriesByKeys(textA)
String ppB = JsonPrettyPrinter.orderMapEntriesByKeys(textB)

// compare 2 converted JSON texts
differ.diffStrings(ppA, ppB, "build/tmp/testOutput/")

In the latter diff report, both JSON are converted by the com.kazurayam.ks.JsonPrettyPrinter class to have the same order of Map entries by keys. Eventually the report clearly shows that FileA and FileB are similar.

Which diff report do you like? — You can choose either of them since the com.kazurayam.ks.TestsDiffer and com.kazurayam.ks.JsonPrettyPrinter are provided. You can produce both reports.

The original post by @philippe.novikov was a bit ambiguous. He wrote 2 different requirements mixed up.

  1. He wants to verify a single complex JSON response.
  2. He wants to compare 2 JSON instances to find the difference between the two

These 2 requirements deserve solutions for each.

@bionel and @joost.degeyndt suggested a solution for the 1st requirement. They proposed validating a JSON instance against a JSON schema. This article introduces the networknk json validator. Katalon Studio v8.6.8 bundles its jar. It is ready to use in KS.

I suggested a solution for the 2nd requirement.

Both solutions are possible in Katalon Studio. Now it’s the turn of the original poster to decide which way to take, or even both.

1 Like