1

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?

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37

1 Answers1

1

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);
bhusak
  • 1,320
  • 1
  • 9
  • 19