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

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

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.

REST Assured Tutorial 56 – JSON Schema Validation Without Rest Assured

by Amod Mahajan time to read: 3 min
0
%d bloggers like this: