# Newman tv4 schema validation does not work

**URL:** <https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923>\
**Category:** Help Hub\
**Created:** [April 10, 2019, 12:08am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923 "2019-04-10T00:08:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjayaram](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rjayaram](https://community.postman.com/u/rjayaram)\
**Post date:** [April 10, 2019, 12:08am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/1 "2019-04-10T00:08:28Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

Problem: My newman tests are working fine except schema validation using tv4.  
Here is the error. It says missing required property QIS. However the response body has “QIS”.

Validation errors:

17:00:59.508

- 
  - Object:{}
    - message:“Missing required property: QIS”
    - name:“ValidationError”
    - type:“Error”

Here is the code snippet:

```auto
 pm.test("Test 18: Response body is valid", function () {
   console.log({
     schema1: globals['search_response_schema']
   });

   data = JSON.parse(responseBody);

   var schema_response = JSON.parse(globals['search_response_schema'])
   console.log("schema_response2 =: ", schema_response)

   //Reference: https://stackoverflow.com/questions/48098530/how-do-i-test-json
   valid = tv4.validate(data, schema_response, true, true);
   tv4.validateResult(request, globals['search_response_schema']).valid;

   console.log("Validation errors: ", tv4.error);
   if (valid !== true) {
     console.log(tv4.error);
   }

   pm.expect(valid).to.be.true;
 });

```

Note: On the console it is logging the schema correctly

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [April 10, 2019, 5:19am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/2 "2019-04-10T05:19:42Z")

</div>

Hi @rjayaram, this issue cannot be triaged by just using this code snippet.  
Can you share a sample (retract any sensitive information) of your response body and a sample of the schema (retract any sensitive information) for us to test this script and then maybe the community will be able to help you better?

Thanks!

---

<div class="post-metadata">

**Author:** ![rjayaram](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rjayaram](https://community.postman.com/u/rjayaram)\
**Post date:** [April 10, 2019, 2:38pm UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/3 "2019-04-10T14:38:32Z")

</div>

Hi Sivcan

Thanks for looking into this. As I could not attach the sample file here I am sending the sample schema and response body pasted into a document and attaching to your email.

Thanks

---

<div class="post-metadata">

**Author:** ![rjayaram](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rjayaram](https://community.postman.com/u/rjayaram)\
**Post date:** [April 10, 2019, 2:43pm UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/4 "2019-04-10T14:43:38Z")

</div>

Sivcan

Thanks for looking into this. As I could not attach the sample file in community site, I am attaching a PDF with the sample schema and response body pasted into a document.

(Attachment PDF\_APR10\_Postman\_Schema\_Validation\_Error.pdf is missing)

---

<div class="post-metadata">

**Author:** ![rjayaram](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rjayaram](https://community.postman.com/u/rjayaram)\
**Post date:** [April 10, 2019, 2:51pm UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/5 "2019-04-10T14:51:43Z")

</div>

Hi

Both email and this community thread rejected a PDF document attachment. Sending the response body and schema in PNG format.

 ![PNG1_responseBody](https://us1.discourse-cdn.com/getpostman/original/3X/1/7/17fa9e363a5295fc65bbc4be295468963f43638d.png) !

Pasted schema below from pre-req script as I could not attach:

var search\_response\_schema =  
{  
“definitions”: {},  
“$schema”: “[http://json-schema.org/draft-07/schema#](http://json-schema.org/draft-07/schema#)”,  
“$id”: “[http://example.com/root.json](http://example.com/root.json)”,  
“type”: “object”,  
“title”: “The Root Schema”,  
“required”: [  
“timing”,  
“data”  
],  
“properties”: {  
“timing”: {  
“$id”: “#/properties/timing”,  
“type”: “array”,  
“title”: “The Timing Schema”,  
“items”: {  
“$id”: “#/properties/timing/items”,  
“type”: “object”,  
“title”: “The Items Schema”,  
“required”: [  
“QIS”  
],  
“properties”: {  
“QIS”: {  
“$id”: “#/properties/timing/items/properties/QIS”,  
“type”: “object”,  
“title”: “The Qis Schema”,  
“required”: [  
“duration”,  
“reqId”  
],  
“properties”: {  
“duration”: {  
“$id”: “#/properties/timing/items/properties/QIS/properties/duration”,  
“type”: “integer”,  
“title”: “The Duration Schema”,  
“default”: 0,  
“examples”: [  
385  
]  
},  
“reqId”: {  
“$id”: “#/properties/timing/items/properties/QIS/properties/reqId”,  
“type”: “string”,  
“title”: “The Reqid Schema”,  
“default”: “”,  
“examples”: [  
“6c845d80-5a23-11e9-bc8f-25dc5895059c”  
],  
“pattern”: “^(._)$"  
}  
}  
}  
}  
}  
},  
“data”: {  
“$id”: “#/properties/data”,  
“type”: “array”,  
“title”: “The Data Schema”,  
“items”: {  
“$id”: “#/properties/data/items”,  
“type”: “object”,  
“title”: “The Items Schema”,  
“required”: [  
“id”,  
“type”,  
“attributes”  
],  
“properties”: {  
“id”: {  
“$id”: “#/properties/data/items/properties/id”,  
“type”: “string”,  
“title”: “The Id Schema”,  
“default”: “”,  
“examples”: [  
“apps”  
],  
“pattern”: "^(._)$”  
},  
“type”: {  
“$id”: “#/properties/data/items/properties/type”,  
“type”: “string”,  
“title”: “The Type Schema”,  
“default”: “”,  
“examples”: [  
“source”  
],  
“pattern”: “^(._)$"  
},  
“attributes”: {  
“$id”: “#/properties/data/items/properties/attributes”,  
“type”: “object”,  
“title”: “The Attributes Schema”,  
“required”: [  
“total\_count”,  
“results”  
],  
“properties”: {  
“total\_count”: {  
“$id”: “#/properties/data/items/properties/attributes/properties/total\_count”,  
“type”: “integer”,  
“title”: “The Total\_count Schema”,  
“default”: 0,  
“examples”: [  
1  
]  
},  
“results”: {  
“$id”: “#/properties/data/items/properties/attributes/properties/results”,  
“type”: “array”,  
“title”: “The Results Schema”,  
“items”: {  
“$id”: “#/properties/data/items/properties/attributes/properties/results/items”,  
“type”: “object”,  
“title”: “The Items Schema”,  
“required”: [  
“attributes”  
],  
“properties”: {  
“attributes”: {  
“$id”: “#/properties/data/items/properties/attributes/properties/results/items/properties/attributes”,  
“type”: “object”,  
“title”: “The Attributes Schema”,  
“required”: [  
“app”,  
“app\_array”  
],  
“properties”: {  
“app”: {  
“$id”: “#/properties/data/items/properties/attributes/properties/results/items/properties/attributes/properties/app”,  
“type”: “string”,  
“title”: “The App Schema”,  
“default”: “”,  
“examples”: [  
“Photoshop”  
],  
“pattern”: "^(._)$”  
},  
“app\_array”: {  
“$id”: “#/properties/data/items/properties/attributes/properties/results/items/properties/attributes/properties/app\_array”,  
“type”: “array”,  
“title”: “The App\_array Schema”,  
“items”: {  
“$id”: “#/properties/data/items/properties/attributes/properties/results/items/properties/attributes/properties/app\_array/items”,  
“type”: “object”,  
“title”: “The Items Schema”,  
“required”: [  
“score”,  
“name”  
],  
“properties”: {  
“score”: {  
“$id”: “#/properties/data/items/properties/attributes/properties/results/items/properties/attributes/properties/app\_array/items/properties/score”,  
“type”: “integer”,  
“title”: “The Score Schema”,  
“default”: 0,  
“examples”: [  
1  
]  
},  
“name”: {  
“$id”: “#/properties/data/items/properties/attributes/properties/results/items/properties/attributes/properties/app\_array/items/properties/name”,  
“type”: “string”,  
“title”: “The Name Schema”,  
“default”: “”,  
“examples”: [  
“Photoshop”  
],  
“pattern”: “^(.\*)$”  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
};

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [April 11, 2019, 6:39am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/7 "2019-04-11T06:39:28Z")

</div>

I am sorry, but PNG cannot be used to debug this issue.  
Will be needing the response JSON to actually test out the script.

You can just type six backticks (`) and paste a sample response in b/w them here instead of uploading a pdf file.  
Also, make sure it’s the correct sample response and a valid JSON.

Please refer the following on how to format code blocks: [https://help.github.com/en/articles/creating-and-highlighting-code-blocks](https://help.github.com/en/articles/creating-and-highlighting-code-blocks)

You can check if your response JSON is valid or not here: [https://jsonlint.com/](https://jsonlint.com/)

Thanks!

---

<div class="post-metadata">

**Author:** ![rjayaram](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rjayaram](https://community.postman.com/u/rjayaram)\
**Post date:** [April 15, 2019, 6:23am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/8 "2019-04-15T06:23:26Z")

</div>

Hi Sivan

I tried pasting the response body within backticks. It gives it exceeds the limit. Let me know where I can paste the response body.

Regards

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [April 15, 2019, 6:30am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/9 "2019-04-15T06:30:10Z")

</div>

You can just paste it here: [https://codeshare.io/G6MOng](https://codeshare.io/G6MOng)

Make sure it’s just an example and not the complete response body.  
Also, please check that it’s valid JSON.

---

<div class="post-metadata">

**Author:** ![rjayaram](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rjayaram](https://community.postman.com/u/rjayaram)\
**Post date:** [April 15, 2019, 6:36am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/10 "2019-04-15T06:36:45Z")

</div>

Done. Pl remove the response from the above link after you copy for debugging.

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [April 15, 2019, 7:00am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/11 "2019-04-15T07:00:41Z")

</div>

@rjayaram I saw that the response body doesn’t have the QIS property, that’s at least what the error was thrown.

For eg (one of the errors):  
At the beginning of the response, it says that `sparkTemplates` has the required property QIS missing.  
So, I added a random `QIS` property to the sparkTemplates object and then the error went away. But yes, there are more validation errors that came after that.  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/5/f/5f295e7f900287ec750a9f7fb712e29e4e6d04d1.png)

You can update your script like so to debug even better:

```javascript
pm.test("Test 18: Response body is valid", function () {
   data = resp;

   var schema_response = JSON.parse(globals['search_response_schema']);
   console.log({ schema_response });
   
   // More detailed error, so that you can see where the validation fails
   tv4.setErrorReporter(function (error, data, schema) {
    return { e: "Error: " + error.code, data };
   });

   //Reference: https://stackoverflow.com/questions/48098530/how-do-i-test-json
   valid = tv4.validate(data, schema_response, true, true);

   console.log({ valid });
   console.log("Validation errors: ", tv4.error);
   if (valid !== true) {
     console.log(tv4.error);
   }

   pm.expect(valid).to.be.true;
});

```

Also, you can open the DevTools for an easier view of the console logs, also with the modified script that I wrote above that gives more detailed error message, you can check that where exactly the validation is failing (on which piece of data).  
You can click on **View \> Developer \> Show DevTools (Current View)**

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/6/4/64fae68504a82626aa68ae92ffe8f01066bc3231.jpeg)

It shows that the response has some issues / the schema has some issues.  
If you think there’s no issue there, then it looks like an issue with the tv4 library itself.

You can locally setup a node project and verify with tv4, whether it’s actually working or not.  
tv4 repo: [GitHub - geraintluff/tv4: Tiny Validator for JSON Schema v4](https://github.com/geraintluff/tv4)

---

<div class="post-metadata">

**Author:** ![rjayaram](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rjayaram](https://community.postman.com/u/rjayaram)\
**Post date:** [April 15, 2019, 7:17am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/12 "2019-04-15T07:17:43Z")

</div>

Hi

As you can see from my response schema and actual response ,“QIS” is present. I think it is an issue with tv4 library itself as some people mentioned in stackoverflow. could you suggest an efficient way / tool to validate schema with postman newman scripts.

Thanks.

---

<div class="post-metadata">

**Author:** ![rjayaram](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rjayaram](https://community.postman.com/u/rjayaram)\
**Post date:** [April 18, 2019, 10:47pm UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/13 "2019-04-18T22:47:05Z")

</div>

Hi Postman team

I am following up on my earlier query. Please suggest a better schema validation library.  
As I mentioned earlier there are no issues with the schema. I see some posts on stackoverflow that tv4 has issues.

Thanks, Rjayaram

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [April 19, 2019, 5:19am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/14 "2019-04-19T05:19:43Z")

</div>

You can use `ajv` which is also built into postman.

AJV Docs - [https://github.com/epoberezkin/ajv](https://github.com/epoberezkin/ajv)

You’ll have to require [ajv in the test script.](https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference/#require)

---

<div class="post-metadata">

**Author:** ![rjayaram](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rjayaram](https://community.postman.com/u/rjayaram)\
**Post date:** [April 19, 2019, 5:23am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/15 "2019-04-19T05:23:31Z")

</div>

Hi Sivcan

Thanks. could you share some postman tests example using ajv for schema validation.

Thx

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [April 19, 2019, 5:24am UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/16 "2019-04-19T05:24:35Z")

</div>

Example:

```javascript
var Ajv = require('ajv'),
    ajv = new Ajv({ logger: console }),
    schema = {
        "properties": {
            "alpha": {
                "type": "boolean"
            }
        }
    };

pm.test('Schema is valid', function() {
    pm.expect(ajv.validate(schema, { alpha: true })).to.be.true;
    pm.expect(ajv.validate(schema, { alpha: 123 })).to.be.false;
});

```

---

<div class="post-metadata">

**Author:** ![ola100](https://avatars.discourse-cdn.com/v4/letter/o/8c91f0/32.png) [@ola100](https://community.postman.com/u/ola100)\
**Post date:** [May 7, 2019, 3:20pm UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/17 "2019-05-07T15:20:19Z")

</div>

@singhsivcan … Thanks for Ajv snippet, its been helpful to some point, but please if you will indulged me , am trying to validate a schema response body of a post with with ajv and its passing even though it should fail … i can see in your snippet that you drill down a to “alpha” property before validation.

How do i validate the response body of a post with the predefined schema.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [May 7, 2019, 3:33pm UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/18 "2019-05-07T15:33:22Z")

</div>

If you could share a sample response and the schema with me, I’ll try to debug it on my end.  
Currently, I can’t guess what might be going wrong.

Thanks!

---

<div class="post-metadata">

**Author:** ![ola100](https://avatars.discourse-cdn.com/v4/letter/o/8c91f0/32.png) [@ola100](https://community.postman.com/u/ola100)\
**Post date:** [May 7, 2019, 3:38pm UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/19 "2019-05-07T15:38:19Z")

</div>

```javascript
 {
    "fl": [
        {
            "fl_Ref": "test_test",
            "dimension": [
                {
                    "dimensionTypeValue": "SE",
                    "dimensionTypeRef": "PD",
                    "dimensionTypeValueRef": "PA"
                },
                {
                    "dimensionTypeValue": "Corporate ",
                    "dimensionTypeRef": "OR",
                    "dimensionTypeValueRef": "CB"
                }
            ],
            "fl_Key": "5cd1a2947a3c4",
            "fl_Name": "test_test",
            "links": []
        }
    ]
}

```

apologies i couldn’t get sample response in well formatted code view …am not too familiar with the features in the forum ☹

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [May 7, 2019, 7:27pm UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/21 "2019-05-07T19:27:06Z")

</div>

I wanted both, the response and the schema that you’ve written.

---

<div class="post-metadata">

**Author:** ![ola100](https://avatars.discourse-cdn.com/v4/letter/o/8c91f0/32.png) [@ola100](https://community.postman.com/u/ola100)\
**Post date:** [May 8, 2019, 4:45pm UTC](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923/22 "2019-05-08T16:45:34Z")

</div>

@singhsivcan thanks in advance for your response and assistance below is the schema  
Schema == \>

```javascript
let Ajv = require('ajv'),
  ajv = new Ajv({ logger: console }), 
  schema = {
    "title": "FlConfiguration",
    "description": "Configuration for a Fl",
    "version": "1-0-3",
    "type": "object",
    "additionalProperties": false,
    "required": [
        "flRef",
        "flName"
    ],
    "properties": {
        "flRef": {
            "description": "Fl reference - external key for underlying configuration. Also used to auto-generate target references",
            "type": "string",
            "pattern": "^[a-zA-Z0-9_-]{0,10}$"
        },
        "flKey": {
            "description": "Internal key for Tag within underlying datastore ",
            "type": "string"
        },
        "flName": {
            "description": "Name of the flow",
            "type": "string"
        },
        "flBuilderVersion": {
            "description": "Version of component used to generate the fl",
            "type": "string"
        },
        "sourceType": {
            "description": "Underlying Source Type",
            "enum": [
                "Refer",
                "Inter",
                "Exter",
                "Syst"
            ]
        },
        "dimension": {
            "description": "Dimensions",
            "type": "array",
            "items": {
                "type": "object",
                "required": [
                    "dimensionTypeRef",
                    "dimensionTypeValueRef"
                ],
                "properties": {
                    "dimensionTypeRef": {
                        "description": "Reference for underlying Dimension type",
                        "type": "string"
                    },
                    "dimensionTypeValueRef": {
                        "description": "Reference for value associated with underlying Dimension Type",
                        "type": "string"
                    },
                    "dimensionTypeValue": {
                        "description": "Dimension value",
                        "type": "string"
                    }
                }
            }
        },
        "lanes": {
            "description": "Swim lanes for fl visuals",
            "type": "array",
            "items": {
                "type": "object"
            }
        },
        "steps": {
            "description": "Process steps within the fl visuals",
            "type": "array",
            "items": {
                "type": "object"
            }
        },
        "links": {
            "description": "Links between process steps",
            "type": "array",
            "items": {
                "type": "object"
            }
        },
        "maps": {
            "description": "(Top-level) fl maps",
            "type": "array",
            "items": {
                "type": "object"
            }
        }
    }
}

```

Response ==\>

```javascript
{
    "fl": [
        {
            "fl_Ref": "test_test",
            "dimension": [
                {
                    "dimensionTypeValue": "SE",
                    "dimensionTypeRef": "PD",
                    "dimensionTypeValueRef": "PA"
                },
                {
                    "dimensionTypeValue": "Corporate ",
                    "dimensionTypeRef": "OR",
                    "dimensionTypeValueRef": "CB"
                }
            ],
            "fl_Key": "5cd1a2947a3c4",
            "fl_Name": "test_test",
            "links": []
        }
    ]
}

```

[Next page](https://community.postman.com/t/newman-tv4-schema-validation-does-not-work/4923.md?page=2)
