0

We have scenario where there is GET API call which extracts "excel" file data from file given file location in the GET call Body.

Using: RestAssured with Cucumber BDD

The Response comes as:

"{\"('Test\/Test1', 'Text')\":{\"0\":\"abc\",\"1\":null,},\"('Test ID', 'Text')\":....:null}}"

Trying to have "Assert" to the text value coming in the Response body.

Tried below ways:

String details = response.jsonPath().get("Test\/Test1");

System.out.println("loan details value is: " + details);

Getting error as:

io.restassured.path.json.exception.JsonPathException: Failed to parse the JSON document
at io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:986)
at io.restassured.path.json.JsonPath$4.doParseWith(JsonPath.java:951)
at io.restassured.path.json.JsonPath$JsonParser.parseWith(JsonPath.java:1031)
at io.restassured.path.json.JsonPath.get(JsonPath.java:202)
at com.xxx.stepdefinition.Co_APIs_StepDen.extract_validated_successfully(Core_APIs_StepDen.java:62)
at ?.Validate the extracted details are retrieved successfully(C:/Users//src/test/java/com/Co_POST_ExtractDetails.feature:17)

Caused by: groovy.json.JsonException: A JSON payload should start with an openning curly brace '{' or an openning square bracket '['. Instead, '"{"('Test/Test1', 'Text')":

Please guide.

la1
  • 519
  • 1
  • 8
  • 30
  • Are you trying to assert that the string in the response contains "Test\/Test1"? – AutoTester213 May 19 '20 at 10:24
  • How does your response look like ? Does it `exactly` look like the one you have posted with the double quotes ? Post the exact response – Wilfred Clement May 19 '20 at 11:07
  • @WojtekT yes, trying to validate/assert to check the 'string' value in the response body. – la1 May 19 '20 at 11:51
  • 1
    The JSON which is fetched back has escape characters in it, and using `.jsonpath()` will not help here since the JSON should be proper. Either extract the response as string and unescape the characters and then use `jsonPath` or extract the response as string and assert on the same string using Hamcrest `assertThat(res,containsString("Test\\/Test1"));` – Wilfred Clement May 19 '20 at 12:35

0 Answers0