Compare two JSON postman responses using comparison tool

Is it possible to automate two Postman responses in JSON format using any comparison tools?
If yes, any suggestions in script.

You just want to compare that both responses have identical properties and property values?

Hi Allen,

Yes, I want to compare if both are having identical properties and values or not

You could use lodash to do this.

In your first request in the test section you can add the following:

const response = pm.response.json();
pm.environment.set('firstResponse', JSON.stringify(response));

Then in the test section of your second request, you could add:

pm.test('Response is idential to other response', function() {
    const firstResponse = JSON.parse(pm.environment.get('firstResponse'));
    const secondResponse = pm.response.json();

    const isEqual = _.isEqual(firstResponse, secondResponse);

That should do what you’re looking for.

Hi Allen,
thanks for the above one and used it in my script as well.

But I have one query:
1st response:

	"Name": "XYZ",
	"Gender": "Male"}
	{"Group": "Mid",
	"Type": "Early"}]

2nd response:

	"Name": "XYZ",
	"Gender": "Male",
	"Group": "Mid",
	"Type": "Early"}

When i compare the above ones, my test is failing because of braces mismatch.

How to sort this out?

The first response doesn’t even look like valid JSON to me so if that’s being returned, is that a different problem :smiley:

The second one is also missing a , between the 2 objects in the array :thinking:

1 Like

I have corrected the responses now. I made a typo error.

I use a free online tool called DeltaJSON from DeltaXML. It allows compare and merge, by analysing the structure rather than line by line, so is more effective for JSON files where the properties and values move around in the file. It can give a delta file to for the changes.

To automate the process you could write a script to retrieve the JSON files and then post them to the REST service they provide.

For a simple manual comparison you could use JSON Diff.