Make Selenium Easy

REST Assured Tutorial 56 – JSON Schema Validation Without Rest Assured

Introduction

As a part of End to End REST Assured Tutorial, in this post, we will learn about JSON Schema validation without Rest Assured.

We have already covered JSON Schema Validation In Rest Assured. You may be wondering why do we need to validate JSON schema without Rest Assured. We just not validate JSON response schema but we should validate JSON request payload as well just to ensure if the payload is correct. If we create it dynamically or get it through external sources we must have a schema check before we pass that payload to API.

We may need to verify schema of any JSON and it should not be restricted only through Rest Assured.

We can use json-schema-validator standalone as well. There is no need to use it with Rest Assured only. Something like TestNG can be integrated with Selenium or Rest Assured or any other libraries. We need to add Hamcrest (A Core API and libraries of hamcrest matcher framework) explicitly if want to use it without Rest Assured.

Prerequisite

I am using the below version of json-schema-validator and hamcrest:-

Validate a JSON without Rest Assured

Since schema validation methods of json-schema-validator library create a hamcrest matcher, we must need to add Hamcrest library in our project. Now we can validate schema of any JSON without Rest Assured.

Sample JSON schema

I have stored the below JSON schema outside of resource folder.

Program

If you keep the expected JSON schema in resource folder then you can use matchesJsonSchemaInClasspath also.

You can download/clone the above sample project from here.

You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related posts here, all API manual and automation related posts here, and find frequently asked Java Programs here.

Many other topics you can navigate through the menu.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

1 thought on “REST Assured Tutorial 56 – JSON Schema Validation Without Rest Assured

  1. Hi,
    Thanks for putting on so much effort.
    One of my friends referred your articles and these are really knowledgeable, especially, for beginners. while researching topics on rest api, i came across something called caching mechanism for rest apis. Can you please write a post on how to implement a generic cache for response received from get and post requests?

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.