# Schema validation ignoring array sub-fields type

**URL:** <https://community.postman.com/t/schema-validation-ignoring-array-sub-fields-type/5200>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [April 29, 2019, 1:19pm UTC](https://community.postman.com/t/schema-validation-ignoring-array-sub-fields-type/5200 "2019-04-29T13:19:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fermani](https://avatars.discourse-cdn.com/v4/letter/f/8baadc/32.png) [@fermani](https://community.postman.com/u/fermani)\
**Post date:** [April 29, 2019, 1:19pm UTC](https://community.postman.com/t/schema-validation-ignoring-array-sub-fields-type/5200/1 "2019-04-29T13:19:01Z")

</div>

Hi,

I have the following JSON response:

```
{
    "access": [
        {
            "id": 1,
            "client": "127.0.0.1",
            "apikey": "apikey1",
            "description": "Local call"
        },
        {
            "id": 2,
            "client": "::1",
            "apikey": "apikey2",
            "description": "Local call"
        },
        {
            "id": 3,
            "client": "192.168.0.100",
            "apikey": "apikey3",
            "description": "Remote call"
        }
    ]
}

```

And this JSON Schema:

```
var accessSchema = {
  "items": {
    "type": "object",
    "properties": {
      "access: { 
          "type": "array",
          "items": {
              "properties": {
                  "id": { "type": "string" },
                  "client": { "type": "string" },
                  "apikey": { "type": "string" },
                  "description": { "type": " **integer**" }
              }
          }
      }
    }
  }
}

```

As you can see, I’ve declared description (a string property) as an INTEGER just to get an error. But for my surprise, the following test is returning always TRUE:

```
    pm.test('Valid JSON schema', function() {
        pm.expect(tv4.validate(JSON.parse(responseBody), accessSchema)).to.be.true;
    });

```

What is wrong with my code?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [April 29, 2019, 1:58pm UTC](https://community.postman.com/t/schema-validation-ignoring-array-sub-fields-type/5200/2 "2019-04-29T13:58:22Z")

</div>

Hey @fermani

Welcome to the community 👋

Not sure what was happening for you locally but the JSON Schema you posted wasn’t valid JSON - It was missing a closing `"` at the end of the `access` key.

I’ve used a different Schema validation module that’s built-in to Postman, to help with this question.

> **[GitHub - ajv-validator/ajv: The fastest JSON schema Validator. Supports JSON...](https://github.com/ajv-validator/ajv)**
>
> The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927) - GitHub - ajv-validator/ajv: The fastest JSON schema Validator. Supports J...

It’s very similar to the `tv4` module but is actively maintained.

I mocked out the response body from the question and this seems to be working (failing the test due to the wrong data type).

```
var Ajv = require('ajv'),
    ajv = new Ajv({logger: console}),
    accessSchema = {
        "properties": {
            "access": { 
                "type": "array",
                "items": {
                    "properties": {
                        "id": { "type": "string" },
                        "client": { "type": "string" },
                        "apikey": { "type": "string" },
                        "description": { "type": "integer" }
                      }
                  }
              }
        }
    }

pm.test('Schema is valid', function() {
    pm.expect(ajv.validate(accessSchema, pm.response.json())).to.be.true;
});  

```

 ![05](https://us1.discourse-cdn.com/getpostman/original/3X/7/7/77bd48b188360fb951631c44ec9b7f3864f6744a.png)

When the schema data types are correct, the test is passing:

 ![17](https://us1.discourse-cdn.com/getpostman/original/2X/b/b9ae886a091a7e32a37be429a0f35ea01e855063.png)

---

<div class="post-metadata">

**Author:** ![fermani](https://avatars.discourse-cdn.com/v4/letter/f/8baadc/32.png) [@fermani](https://community.postman.com/u/fermani)\
**Post date:** [April 29, 2019, 2:18pm UTC](https://community.postman.com/t/schema-validation-ignoring-array-sub-fields-type/5200/3 "2019-04-29T14:18:16Z")

</div>

It worked, thanks.

I think the problem was my schema, I shouldn’t use the “items” property first. Just removed (after seeing your example) and it worked.
