3

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 cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

I want to comapre 2 objects using TestNG.

I tried in below way but it is giving wrong results.

Assert.assertEquals(actualObject, ExpectedObject);

Can any one help me on this ?

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103

1 Answers1

1

I'd use JSONAssert - https://github.com/skyscreamer/JSONassert

JSONObject data = getRESTData("/friends/367.json");
String expected = "{friends:[{id:123,name:\"Corby Page\"},{id:456,name:\"Carter Page\"}]}";
JSONAssert.assertEquals(expected, data, false);
Ben Yee
  • 1,547
  • 13
  • 19