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
0
votes
1 answer

Jsonassert ignore key

There are 2 Json strings to compare. 1 "values": { "-1487778947": { "field1": "xxx", "field2": "yyy", "field3": { "zzz": { "field4": 21, "field5": 28 } } }, "-1820451085": { …
0
votes
1 answer

Ignore specific attributes when comparing two json files

I have been successfully using JSONAssert to compare two json responses like this: JSONAssert.assertEquals(response2.getResponseBodyContent(), response1.getResponseBodyContent(), JSONCompareMode.LENIENT) I now need to ignore certain attributes as…
M Thurman
  • 41
  • 1
  • 7
0
votes
1 answer

How comapre 2 json filtered with multiple json path with single comparisson?

There are 2 json, there multiple paths which is needed to be applied on both json. Then these jsons should be compared via some assert in test. The ide solution whould be: Stirng actualJson - .... Stirng expectedJson - .... Stirng actualJsonFiltered…
Cherry
  • 31,309
  • 66
  • 224
  • 364
0
votes
1 answer

Use JSONAssert on part of JSON with RESTAssured

I am able to retrieve JSON from a service using RESTAssured. I would like to use the JSONPath capability to extract JSON and then compare it using JSONAssert. Here's my example: @Test public void doAPITestExample() throws JSONException { //…
0
votes
1 answer

JSONCompareResult does not work with GSON for primitive type integers. Why?

I was playing around with the Gson and JSONAssert libraries when I ran into this problem. I have the following function to compare two integers: private static void runCompareInts(int source, int target){ JSONCompareResult result =…
amad-person
  • 431
  • 1
  • 4
  • 12
0
votes
2 answers

JUnit testing - Best and most reliable way to do my tests?

I'm testing my android app using JUnit. It's the first time I do JUnit testing for real so I don't know the path I should follow. Right now I'm testing the queries to the contacts list. Many methods just require a Raw Contact ID or a Contact ID as a…
dazito
  • 7,740
  • 15
  • 75
  • 117
0
votes
1 answer

How can I remove( and update ) desired field from json ?

I am writing a test code to compare json value. Currently, it am using JSONAssert to compare my json value with api response and work fine. But I think response json might be changed to support more feature. Then JSONAssert could report failed…
user670097
  • 159
  • 1
  • 3
  • 11
-1
votes
1 answer

jmeter: evaluate the values of JSON values

I am trying to test my API response using JSON assertion in JMeter, but couldn't find out on how to achieve it. The API returns 2 values, and I need to check if the difference between these two value are consistent API response: { "start":…
Girish BN
  • 91
  • 2
  • 13
1 2
3