How to solve the Unrecognized token error using WS.ValidateJsonAgainstSchema?

Hi All

I’m trying to validate the schema of a payload request following the logic below.

//Validate Schema for Payload request
String payloadR = (‘Include/resource/PostPayment_Payload.json’)
String payloadReq = (‘Include/resource/RequestPayment.json’)

resultRequest = WS.validateJsonAgainstSchema(payloadR, payloadReq)

		if (resultRequest == true) {
			KeywordUtil.markPassed('Request Schema is in compliance')
		} else {
			KeywordUtil.markFailed('Request Schema is not matching')

However, I’m getting the error:

Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token ‘Include’: was expecting (JSON String, Number, Array, Object or token ‘null’, ‘true’ or ‘false’)

Does someone have any idea?

I do not think you are implementing WS.validateJsonAgainstSchema correctly.

You are passing a String to WS.validateJsonAgainstSchema but it is expecting a JSON String. That is not the same thing.

If I look at the payloadR and payloadReq you set, you are trying to set these strings equal to the contents of the files called PostPayment_Payload.json and RequestPayment.json

So you will first need to set the strings equal to the contents of these files and not the string of where to locate these files.

Please have a look at the documentation again and take note of how the strings are written in the examples.

As mentioned, this is wrong.
Assuming PostPayment_Payload.json is a text file located under Include/resource folder, you have to use something like:

def payloadR = new File('Include/resource/PostPayment_Payload.json').text