I have a JSON response which returns all the details of the users in a company. I have converted those responses to JSON schema and kept it in a file name JSONSchema.json.
Now how do I compare all the responses with the JSON schema ? Can someone please help.
JSON Data
[ {
"Id": 2,
"Name": "Test123",
"Status": "Active"
},
{
"Id": 3,
"Name": "123Test",
"Status": "Active"
}
]
JSON Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"items": [
{
"type": "object",
"properties": {
"Id": {
"type": "integer"
},
"Name": {
"type": "string"
},
"Status": {
"type": "string"
}
},
"required": [
"Id",
"Name",
"Status"
]
},
{
"type": "object",
"properties": {
"Id": {
"type": "integer"
},
"Name": {
"type": "string"
},
"Status": {
"type": "string"
}
},
"required": [
"Id",
"Name",
"Status"
]
}
]
}
Code
*** Settings ***
Library jsonschema
*** Test Cases ***
${get_value}= GET On Session xyz /details
${json_response}= set variable ${get_value.json()}
${schema} Get Binary File ./myschema.json
${schema} evaluate json.loads('''${schema}''') json
${instance} evaluate json.loads('''{"Name":[0,1]}''') json
validate instance=${instance} schema=${schema}
I have issues with the last two lines of the code.
I want the my json response compare to the schema as give a pass message when I get compare the Name : Test123 with the type string in JSON schema