Skip to content

Instantly share code, notes, and snippets.

@shay360
Forked from JamesMessinger/json-schema.js
Created May 2, 2018 09:58
Show Gist options
  • Select an option

  • Save shay360/172fa2dc0f1563cda0676a6996da39d9 to your computer and use it in GitHub Desktop.

Select an option

Save shay360/172fa2dc0f1563cda0676a6996da39d9 to your computer and use it in GitHub Desktop.
Using JSON Schema in Postman
// Define the JSON Schema
const customerSchema = {
"required": ["id"],
"properties": {
"id": {
"type": "integer",
"minimum": 100,
"maximum": 1000
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 25
}
}
};
// Test whether the response matches the schema
var customer = JSON.parse(responseBody);
tests["Customer is valid"] = tv4.validate(customer, customerSchema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment