Skip to content

Instantly share code, notes, and snippets.

@JamesMessinger
Created July 27, 2017 19:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JamesMessinger/fba37542221b2128603a480aa1100ad2 to your computer and use it in GitHub Desktop.
Save JamesMessinger/fba37542221b2128603a480aa1100ad2 to your computer and use it in GitHub Desktop.
Using JSON Schema in Postman (via an environment variable)
// Load the JSON Schema
const customerSchema = JSON.parse(environment.customerSchema);
// Test whether the response matches the schema
var customer = JSON.parse(responseBody);
tests["Customer is valid"] = tv4.validate(customer, customerSchema);
@apoo51
Copy link

apoo51 commented Aug 10, 2018

Im getting "AssertionError: expected false to be truthy" error, when i use this method to validate schema

@josephbarsness
Copy link

@apoo51 - did you ever figure out a solution for this issue?

@JamesMessinger
Copy link
Author

Postman just published a video showing how to validate JSON schemas. I recommend watching it, since it goes into far more detail than my little code snippet does.

https://www.youtube.com/watch?v=haDQBmQii2g

@josephbarsness
Copy link

@JamesMessinger thanks so much!!! You have no idea how much this code snippet has helped me and other co-workers of mine... I was able to solve this 'false to be truthy' error by adding in 'false, true' in the .validate function ... the failed test passed after this addition -

var customer = JSON.parse(responseBody);
tests["Customer is valid"] = tv4.validate(customer, false, true, customerSchema);

@AdditionAddict
Copy link

Postman just published a video showing how to validate JSON schemas. I recommend watching it, since it goes into far more detail than my little code snippet does.

https://www.youtube.com/watch?v=haDQBmQii2g

Comment for purposes of finding this again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment