Compare JSON response with a JSON schema in ROBOT

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"
      ]
    }
  ]
}

There’s Python packages that do this. I would suggest using those from a custom (Python) library.

You’re looking for the ResponseValidator from GitHub - p1c2u/openapi-core: OpenAPI core.
Now if the API you’re testing is a Swagger / OpenAPI compliant API, you can do away with the manually constructed JSON Schema and just use GitHub - RonnyPfannschmidt/prance: Resolving Swagger/OpenAPI 2.0 and 3.0 Parser to load the openapi.json / openapi.yaml.

I use both these in the OpenApiDriver. For implementation examples, you can use at init() and validate_response() in openapi_executors.py.

1 Like