I'm Using RestAssured, and i'm getting the response like this-
{
"Data": {
"Sub": {
"SubDetails": [
{
"OrgId": 5,
"SubId": 1,
"SubName": "Mathematics"
}
]
}
},
"RawData": {
"Url": "http://localhost:11111/cases/case-15",
"Type": "Rest",
"Request": {
"Details": {
"OrganizationId": 5,
"Student": {
"Age": 30,
"Religion": "Hindu",
"StudentId": 10
}
}
},
"Response": {
"SmartReturnObject": {
"Subject": [
{
"SubjectId": 1,
"SubjectName": "Mathematics"
}
],
"OrganizationId": 5
}
},
"IsApiError": false
},
"SessionId": "5q0",
"RequestUniqueId": "4543534",
"StatusCode": "4540000",
"StatusMessage": "Success",
"DataSource": "DD"
}
Now i need to extract the Data object separate and RawData separate but I failed.
I tried with JSONPath also but not getting it in JSON format.
I tried
JsonPath body= response.jsonPath();
Object value=body.get("Data");
System.out.println("Value is-"+value);
and getting it like this - {Sub={SubDetails=[{OrgId=5, SubId=1, SubName=Mathematics}]}}
I want the response as instanceof JSONObject or JSONArray type.Response can be dynamic like JSONObject
or JSONArray
can be at any place.
1 Answer 1
Why is this not an option?
JsonPath resJson= new JsonPath(response);
JsonPath referrenceJson= new JsonPath(jsonTOCompare);
Assert.assertEquals(resJson.get("fields"), referrenceJson.get("fields"));
-
Because i want to compare each property, and if any mismatch happen then i need to know that whether key not matched or any value not matched. Also some time i got the scenario like i need to ignore the some property during compare.Upkar Singh– Upkar Singh2020年01月22日 06:26:47 +00:00Commented Jan 22, 2020 at 6:26
-
Could you provide a real example of what you tried to achieve but failed? Something that you think it will not work with the suggested solution?PDHide– PDHide2020年01月22日 19:42:02 +00:00Commented Jan 22, 2020 at 19:42
-
you can edit the question add something like i wanted to compare {a:1} with [{a:2}] . Tried suggested answer but got this errorPDHide– PDHide2020年01月22日 19:46:39 +00:00Commented Jan 22, 2020 at 19:46
-
1I need to compare the response json to json coming from .json file, by using your way i can't do that until i will not get the response in instance of JSONObject or JSONArray.Upkar Singh– Upkar Singh2020年01月24日 05:28:34 +00:00Commented Jan 24, 2020 at 5:28
Explore related questions
See similar questions with these tags.
Data
object andRawData
object separately from response, in instanceofJSONObject
orJSONArray
type (in whatever format response is)