Table of contents
1.
Introduction🤓
2.
Schema Validation in Postman💁🏻
3.
Reasons why Schema Validation is required! 😲
4.
Object Response in Schema Validation🤠
5.
Optional Property of Object in Schema Validation 🧾
6.
Required Property of Object in Schema Validation📂
7.
Nested Objects in Schema Validation
8.
Frequently Asked Questions
8.1.
How do you validate data in Postman?
8.2.
What is a JSON Schema file?
8.3.
Why do we need JSON Schema validation?
9.
Conclusion
Last Updated: Mar 27, 2024

What do Schema Validations mean in Postman?

Author Sagar Mishra
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction🤓

JSON stands for JavaScript Object Notation. JSON Schema validation asserts limits on the instance data's structure. Once all asserted needs have been met, any keywords containing non-assertion information, such as usage tips and descriptive metadata, are later annotated on an instance location that fulfills all of the criteria.

logo

In this article, we will discuss what is schema validation in Postman.

Schema Validation in Postman💁🏻

The JSON Schema spec defines the expected data types and formats for each field in the response. It provides clear, machine and human-readable documentation that describes the current data format and allows for full structural validation. This is helpful for automated testing as well as validating data that clients have submitted.

discussion

Reasons why Schema Validation is required! 😲

JSON Schema Validation in Postman is required because of the below reasons:

🔷 We keep an eye on API responses to ensure the format we receive is the same as expected.

🔷 It is simpler to verify that an API is returning valid data when we build a model of the API response using JSON Schema.

🔷 We receive alerts whenever a JSON response undergoes a breaking change.

Object Response in Schema Validation🤠

In this section of "Schema Validation in Postman," we will discuss the syntax with an example using Object Response.

In general, the JSON response looks like a curly brace, and the syntax is as follows:

{ }

 

And the syntax of JSON schema in Object Response is as follows:

const schema = { "type": "object" }; 

 

Syntax of testing a JSON schema in Object Response is:

pm.test("Validate schema", () => { 
	pm.response.to.have.jsonSchema(schema); 
}); 

Optional Property of Object in Schema Validation 🧾

In this section of "Schema Validation in Postman," we will discuss the syntax of the Optional Property of Object in Schema Validation. 

The JSON response of the Optional Property looks like the below:

{ 
	"code": "FX002"
}

 

Syntax of JSON schema having type and property name.

const schema = { 
	"type": "object", 
	"properties": { "code": { "type": "string" } 
	} 
}; 

 

We have a lot of options for the "type" field. For example:

👉🏻 number

👉🏻 null

👉🏻 array

👉🏻 string

👉🏻 boolean

👉🏻 Object

Required Property of Object in Schema Validation📂

In this section of "Schema Validation in Postman," we will discuss the syntax of Required Property of Object in Schema Validation. 

In the below example, note that JSON schema with a property named "code" of type String is the required property: 

Let's take a look at the given JSON response:

{ 
	"code": "FX002"
}

 

Syntax of JSON schema with property name and type:

const schema = { "type": "object", "properties": { "code": { "type": "string" } }, "required": ["code"] }; 

Nested Objects in Schema Validation

In this section of "Schema Validation in Postman," we will discuss the syntax of Nested Object in Schema Validation. 

Objects that are placed inside one another are called Nested Objects. Within a nested object, you can build other nested objects.

The syntax of Nested Objects is as follows:

JSON response:

{ "code": "2", "error": { "message": "Not permitted." } } 

 

JSON Schema:

const schema = { 
	"type": "object", 
	"properties": { 
		"code": { "type": "string" }, 
		"error": { 
			"type": "object", 
			"properties": { 
				"message": { "type": "string" } 
			}, "required": ["message"] 
		} 
	}, 
	"required": ["code", "error"]
}; 

Frequently Asked Questions

How do you validate data in Postman?

Your collection needs to be connected to an API if you want your requests validated. If you create a collection from a schema or add it as a relation to an existing API, the collection is linked to the API. Postman checks a request before it is dispatched.

What is a JSON Schema file?

The IETF standard, known as JSON Schema, provides a format for the JSON data needed and how to interact with it. Applying such standards to a JSON document may ensure that related JSON data is consistent and accurate.

Why do we need JSON Schema validation?

The key benefit of JSON Schema is that it produces machine- and human-friendly documentation. The data structure can be precisely described in form developers can efficiently utilize for automated validation. This makes the job easier for testers and developers, but the benefits go beyond productivity.

Check this out :  what is schema in dbms

Conclusion

We have discussed the topic of Schema Validation in Postman. We have seen why Schema Validation is important, Object response, Optional property, Required property, and Nested Objects in Schema Validation.

We hope this blog has helped you enhance your knowledge of Schema Validation in Postman. If you want to learn more, check out our articles Commands of JSONJSON Clients in RedisDeveloper Notes on Redis, and many more on our platform Coding Ninjas Studio.

But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundles for placement preparations.

However, you may consider our paid courses to give your career an edge over others!

Happy Learning!

Live masterclass