Questions tagged [jsonassert]

JSONAssert is a Java library for simplifying JUnit tests which need to compare complex JSON structures.

JSONAssert is an open-source library aimed at simplifying JUnit tests which need to compare complex JSON structures.

The tests contain simple assertions which resemble string comparisons, e.g.:

final String actual = ...; // get JSON string from a REST endpoint
final String expected = 
    "{success:true, items: [{id:4711, name:\"Cat\"}, {id:1147,name:\"Squirrel\"}]}";
JSONAssert.assertEquals(expected, actual, false);

The library parses the strings into JSON objects and compares their logical structures.

JSONAssert can also compare org.json objects.

39 questions
37
votes
4 answers

Ignore specific nodes/attributes while comparing two JSONs

I want to compare two JSON strings which is a huge hierarchy and want to know where they differ in values. But some values are generated at runtime and are dynamic. I want to ignore those particular nodes from my comparison. I am currently using…
Prateik
  • 545
  • 1
  • 5
  • 12
13
votes
7 answers

How to compare two jsons ignoring order of elements in array properties?

I need to compare two strings which represent json objects. For testing purposes I need a way to compare these strings ignoring not only the child elements order (which is quite common) but order of elements in array properties of jsons.…
Vladimir
  • 12,753
  • 19
  • 62
  • 77
10
votes
2 answers

Ignore specific node within array when comparing two JSON in Java

I want to compare two JSON strings in Java 8 for equality, but ignore specific known nodes which contain values which are expected to be different and are a tolerated difference e.g. timestamp. Currently using JSONAssert v1.5.0 from org.SkyScreamer,…
Mark H
  • 111
  • 1
  • 5
7
votes
2 answers

Are there any new JSONAssert alternatives having compare modes?

I wonder if there are any alternatives to JSONAssert library which allow asserting a JSON file in a similar way. The Alternative which has a similar feature to JSONCompareMode like STRICT and NON_EXTENSIBLE etc. The last commit in JSONAssert seems…
vmaaik
  • 71
  • 4
5
votes
3 answers

JSON validation using JSONAssert with regular expressions

I am working in a open-source project which uses REST interface. To validate (match actual response with expected) our rest interfaces in the JUnit, we would like to use the JSONAssert. (https://github.com/skyscreamer/JSONassert). But I have a…
5
votes
2 answers

Compare JSON response using JUnit and JSONassert

I'm relatively new to Java and I'm asking to write test of JSON response server. I found JSONassert very useful but I didn't succeed to write the method getRESTData. Anybody can help please? @Test public void testGetFriends() throws JSONException { …
david david
  • 51
  • 1
  • 1
  • 2
3
votes
0 answers

nested Json validation with jsonAssert using regular expression

I need to validate the rest assured response that has nested json against regular expression { "user": { "id": "\\d+", "name": "^((?:[A-Za-z]+ ?){1,3})$", "requires2fa": "true|false" }, "status": "success|failure" } This works…
Sanch
  • 41
  • 4
3
votes
0 answers

Using REST-Assured's ifValidationFails together with JSONAssert

I decided to use REST-Assured for testing REST services. The results are (mostly) JSON and XML documents. For checking JSON, I find JSONassert very helpful. I do not want to compare parts of the body, but the complete body of a response. So, the…
koppor
  • 19,079
  • 15
  • 119
  • 161
3
votes
1 answer

How to compare two json objects using testng

Here I am having 2 JSONObjects with same data as { "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et…
2
votes
1 answer

finding json diff fails using JSONAssert

I was hoping to use Jackson to find JSON diff but it does not give detailed error messages. So I tried using JSOnAssert to find the diff between two JSON strings. JSONAssert.assertEquals(expectedJsonResponse, actualJsonResponse, false); Sadly, it…
likejudo
  • 3,396
  • 6
  • 52
  • 107
2
votes
2 answers

JMeter json path assert json or array in the response

I am doing api testing with Jmeter and using json path assertion to the response body. Problem is response body is giving two response path based on success and failure. for failure { "response": { "error_message": "Invalid input…
Zeeshan
  • 165
  • 1
  • 13
2
votes
1 answer

Ignore specific attribute/fields in jsonassert

I need to compare two json strings by ignore some fields I am currently using JSONAssert from org.SkyScreamer to do the comparison but does not ignore any attributes. Json 1 : { "contributions": [ [ { "order" : 1, …
Rekha k
  • 21
  • 3
2
votes
1 answer

JSONAssert.assertEquals: Ignoring multiple fields when comparing

I have the following JSON structure { "name": "xyz", "address": { "street": "avenida", "number": "41414-44141", "code": "33ll", "moreFields": "some data" }, "moreFields": "some data" } In my JUNIT class I will have to…
bharathp
  • 355
  • 1
  • 5
  • 16
1
vote
1 answer

Error invoking bsh method: eval Sourced file: inline evaluation of: `import org.skyscreamer.jsonassert.Customization; Constructor error: Can't find

I use jmeter to comapre json data.use org.skyscreamer.jsonassert. suceess in idea with jdk8, but failed in jmeter this is error info. i have imported jsonassert-1.5.1.jar and android-json-0.0.20131108.vaadin1.jar into %Jmeter%lib,jackson use…
gangye
  • 11
  • 2
1
vote
1 answer

How to write a json custom comparator for a specific datatype using skyscreamer (JSONAssert)?

How do I write a JSONCustomComparator not for a specific field, but a specific datatype? I know for a specific field, I can do, CustomComparator comparator = new CustomComparator( JSONCompareMode.LENIENT, new…
Optimus Prime
  • 6,817
  • 5
  • 32
  • 60
1
2 3