0

I am having the following response body via rest assured in java

{
"-1": {
    "totalExecutions": 0,
    "endDate": "",
    "description": "",
    "totalExecuted": 0,
    "started": "",
    "versionName": "Unscheduled",
    "expand": "executionSummaries",
    "projectKey": "test",
    "versionId": -1,
    "environment": "",
    "totalCycleExecutions": 0,
    "build": "",
    "ended": "",
    "name": "Ad hoc",
    "modifiedBy": "",
    "projectId": 99,
    "startDate": "",
    "executionSummaries": {
        "executionSummary": [

        ]
    }
},
"7718": {
    "totalExecutions": 1,
    "endDate": "",
    "description": "",
    "totalExecuted": 1,
    "started": "",
    "versionName": "Unscheduled",
    "expand": "executionSummaries",
    "projectKey": "test",
    "versionId": -1,
    "environment": "",
    "totalCycleExecutions": 1,
    "totalDefects": 0,
    "build": "",
    "createdBy": "xyz",
    "ended": "",
    "name": "xyz_SignIn",
    "totalFolders": 0,
    "modifiedBy": "xyz",
    "projectId": 99,
    "createdByDisplay": "xyz",
    "startDate": "",
    "executionSummaries": {
        "executionSummary": [

        ]
    }
},
"recordsCount": 2

}

to extract all the name element values I am using the following code

String[]  test_cycle_values;
JsonPath jsonPathEvaluator = response.jsonPath();
test_cycle_values = jsonPathEvaluator.get("*.[*].name");

the expected outcome I expect is Ad hoc, xyz_signIn

However I am getting Illegal argument exception for JsonPathEvauter

How can I retrive the name values from all the response body? JsonPathEvauter jar version is 3.0.5

If I use test_cycle_values = jsonPathEvaluator.get("7718.name");

I am getting it the value xyz_sign In

Jinx
  • 43
  • 7

1 Answers1

0
.*.name 

this should do your job. Works for me.

jwatts
  • 34
  • 4
  • In order to pass path to jsonPathEvaluator you need to remove $ sign. the issue is that for . or * its throwing an unvalid JSON expression error – Jinx Jan 17 '19 at 14:35
  • Not sure about your environment setup, but you can try using an earlier version of json jar like 2.3.0 and try the above solution ".*.name" . It might work. – jwatts Jan 17 '19 at 15:16
  • My mistake, I am using json-path that's why the above solution didn't worked for me – Jinx Jan 17 '19 at 15:17