cancel
Showing results for 
Search instead for 
Did you mean: 

Json response format assertion

SOLVED
Highlighted
Occasional Contributor

Json response format assertion

Hello everybody,

 

I am looking for a way to find an assertion which could help me  check that I got the json schema in the exact order.

Let'us look at the example below.

I want an assertion whic says that I get "error", then with "message" and "details" nested in this exact order.

I also want to check the content of both "message" and "details".

error.png

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: Json response format assertion

@fmensah 

 

You can verify the data by writing below in script assertion : 

import groovy.json.JsonSlurper

def response = messageExchange.responseContent

def jsonSlurper = new JsonSlurper().parseText(response)

assert jsonSlurper.message == "FLEET_ALREADY_EXISTS" : "Data for message is different"
assert jsonSlurper.details == null : "Data for details is different"

 

I don't think i order matter, what is your use case to match order.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

2 REPLIES 2
Highlighted
Community Hero

Re: Json response format assertion

It does not make any difference if the order gets changed between message, details. Not sure if it is guaranteed as well.

 

Of course, it must pass the Schema compliance. Please refer:

https://support.smartbear.com/readyapi/docs/testing/assertions/reference/compliance/json-schema.html

 

If you want content assertion, then use JSON Path assertion, one for each verification.



Regards,
Rao.
Highlighted
Community Leader

Re: Json response format assertion

@fmensah 

 

You can verify the data by writing below in script assertion : 

import groovy.json.JsonSlurper

def response = messageExchange.responseContent

def jsonSlurper = new JsonSlurper().parseText(response)

assert jsonSlurper.message == "FLEET_ALREADY_EXISTS" : "Data for message is different"
assert jsonSlurper.details == null : "Data for details is different"

 

I don't think i order matter, what is your use case to match order.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors