Christian Baumann
Christian Baumann

Reputation: 3435

Rest Assured Json Path returns Exception

I´m reading json from a file in order to compare it to an http request body´s json.

I´m doing

JsonPath expectedJson = new JsonPath(new File("response.json"));
// some more code
assertThat().body("", equalTo(expectedJson.getMap("")));

which results in JsonPathException: Failed to parse the JSON document

This is the response.json file, which I copied from the response in Postman:

{
  "screenDefinition":{
    "taskId":"account-type",
    "parameters":null
  },
  "prospect":{
    "initializationType":"FIRST_HOLDER",
    "jointAccount":{
      "jointAccountId":655
    },
    "emailConfirmed":false,
    "addressConfirmed":false,
    "emailValidated":false,
    "smsCodeAttemptsLeft":0,
    "mobilePhoneValidated":false,
    "paragraphsAccepted":false,
    "termsConditionsAccepted":false,
    "changedToAutonomousMethod":false,
    "changedToIdentificationMethod":false,
    "contractAccepted":false,
    "prospectOnboardContactType":"NONE",
    "secondAccountHolder":false,
    "evidencesUploaded":false,
    "uploadEvidencesLater":false
  }
}

Any ideas?

Upvotes: 1

Views: 419

Answers (1)

bhusak
bhusak

Reputation: 1390

That JsonPathException you got is probably caused by java.io.FileNotFoundException which means that path to your file is incorrect. Try checking if file exists first:

File file = new File("response.json");
System.out.println("File exists: " + file.exists());
JsonPath jsonPath = new JsonPath(file);

Upvotes: 1

Related Questions