Using AJv to validate Json schema

Hi @phuongphuong99

You won’t need to import AJV like that, it’s already built into Postman.
As explained (about halfway through) in this video; JSON Schema validation in Postman - YouTube


Just been playing around with this and even though the schema appears to validate I think your schema is incorrect.

It doesn’t recognise 1 as an int and there are a few other things that didn’t seem to work right.

I knocked up a new schema with an online JSON to schema converter… the result looks like this;
Note: snipped to keep it short…

const expectSchema = {
    "type": "array",
  "items": [
    {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "available": {
          "type": "boolean"
        }
      },
      "required": [
        "id",
        "name",
        "type",
        "available"
      ]
    }
]
}

The validation looks like this;

and an invalid value;

Hope this helps.

1 Like