Make Selenium Easy

REST Assured Tutorial 60 – Learn to write JsonPath expressions or JsonPath syntax

Introduction

As a part of the End to End REST Assured Tutorial, in this post, we will learn to learn more JsonPath syntax and expressions.

We have already covered the introduction of JsonPath and creating JsonPath for simple and nested JsonObjects and JsonArrays. You can refer to those posts here:-

What Is JsonPath And How To Create It For Simple And Nested JSON Object?

How To Create JsonPath For Simple And Nested JSON Array?

Prerequisite

As we are using RestAssured which includes JsonPath dependency by default, there is no need to include JsonPath dependency explicitly. I have used the below version of Rest Assured for this post:-

Basic concepts of JsonPath supported by Rest Assured

JsonPath in Rest Assured uses Groovy’s GPath notation and is not to be confused with Jayway’s JsonPath syntax. In simple words there are many JsonPath syntaxes you will see around but all will not be supported by RestAssured JsonPath. In this post, we will see all supported JsonPath syntaxes by Rest Assured.

The root node is represented as a “$” sign. While writing JsonPath in RestAssured we do not need to add a dollar sign. The child node of a JSON object can be represented as a dot (.) or using [<childName>]. We can also use [] to represent a particular index element in a JSON array.

Let’s learn syntaxes with examples rather than theory.

Example Program

Output

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.

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.