Shivam Gupta
Shivam Gupta

Reputation: 77

How to Validate variable can have a vale either NULL or in String format

I'm starting to use karate for testing. I need to validate one json response. JSON Schema Design:

response{

 id* Integer Not null
 Name* String can be null

}

now i need to verified id and name with below constraints, id should be integer and should not be null. Name can either in string or can be null.

what equation we can use in Karate.

Thanks in Advances

def jsonValidate = {name: '#integer',Name: '#present'}

so if i use Present here ,it means Name can be null or can have value of any data type. but i need to check Name can be either String or Null Value only

Upvotes: 2

Views: 3071

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58088

Read the docs, and try this: https://github.com/intuit/karate#optional-fields

* def jsonValidate = { id: '#number', name: '##string' }

Upvotes: 3

Related Questions