Confirm the validity of a data point within the JSON data package

When we send a request using the HTTP GET method, the API responds with the data. I need to ensure that the values of a specific input key match exactly what was specified in the GET URL.

The URL that was used for the request:

https://dummy.dns.com/Wells/resource?$filter=employee.address eq 'France FR'

The API provided the following response:

{"next":"https://dummy.dns.com/Wells/resource?$skip=10&$filter=employee.address eq 'France FR'","value":[{"customer.name":"Stefan Peter","customer.landlinePhoneNumber":"97642","employee.country.name":"France","employee.country.id":"FR","employee.address":"France FR","employee.latitude":49,"employee.longitude":7.6,"leave.count":0,"_id":"M1023453","_externalId":"WF3453","_name":"WellsFargo","_employeeType":["contractual"],"_employee":"WF3453","_customer":"M1023453","leave.sickCount":0,"leave.casualCount":0},{"customer.name":"Stefan Peter","customer.landlinePhoneNumber":"97642","employee.country.name":"France","employee.country.id":"FR","employee.address":"France FR Junk","employee.latitude":49,"employee.longitude":7.6,"leave.count":0,"_id":"M1023454","_externalId":"WF3454","_name":"WellsFargo","_employeeType":["contractual"],"_employee":"WF3454","_customer":"M1023454","leave.sickCount":0,"leave.casualCount":0},{"customer.name":"Stefan Peter","customer.landlinePhoneNumber":"97642","employee.country.name":"France","employee.country.id":"FR","employee.address":"France FR","employee.latitude":49,"employee.longitude":7.6,"leave.count":0,"_id":"M1023455","_externalId":"WF3455","_name":"WellsFargo","_employeeType":["contractual"],"_employee":"WF3455","_customer":"M1023455","leave.sickCount":0,"leave.casualCount":0}]}

Now I need to verify that the key-value pairs match the ones I provided in the URL as input/query parameters.

I am utilizing JMeter as my client for API testing. Can someone recommend a custom assertion to validate this? The response contains an array that could potentially grow to 100 or 200 entries. I appreciate any suggestions. Thank you.

Answer №1

To validate the JSON response, utilize the JSON Assertion with the following settings:

  • Verify the existence of JSON PATH: $..value[*].['employee.address']
  • Enable the "Additionally assert value" option
  • Input the expected value as: France FR

https://i.sstatic.net/6PigN.png

Answer №2

  1. Include the JSR223 Assertion within the HTTP Request sampler to evaluate the response
  2. Insert the following code into the "Script" section:

    new groovy.json.JsonSlurper().parse(prev.getResponseData()).value.each { entry ->
        if (!entry.get('employee.address').equals('France FR')) {
            AssertionResult.setFailure(true)
            AssertionResult.setFailureMessage('Expected "France FR", received "' + entry.get('employee.address') + '"')
        }
    }
    
  3. This setup will flag the sampler as failed in case of a mismatch:

    https://i.sstatic.net/P3qe1.png

For further guidance, refer to:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method for breaking down this JSON data into distinct 'objects'?

I am struggling with deserializing JSON data into multiple instances of an object I have defined. Here is how the object is structured: function Question_Value__c () { this.Id=null; this.Name=null; this.Question__c=null; this.Order__c=null ...

Formatting JSON with the directory path using C#

I'm struggling to store a folder path in a json file and I just can't seem to get it right Here is the code I am using to write to the json file: string location = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string u ...

Error message appearing repeatedly and submit button functioning only after second click

I am currently working on my CS50 Final Project, where I am in the process of designing a web app using Flask. Specifically, this issue arises in the login/register page where I am attempting to verify if the username is already taken (through jsonify) and ...

Transforming JSON data into a DataFrame

As a newcomer to JSON, I have combed through various tutorials in an attempt to understand the process better. Seeking additional guidance, I am looking to convert a JSON dictionary into a dataframe using Jupyter notebook/Pandas and eventually save it as a ...

Deleting data in JSON format using Ruby on Rails involves utilizing the appropriate

I am attempting to remove a row from the table using JSON. Here is the delete button code: link_to('Delete', product, method: :delete, data: { confirm: 'Are you sure?' }, remote: true) In the controller: def destroy @product.de ...

Retrieving a result from the reduce function in Angular

Is there a way to use the reduce function in order to return a list of objects? I am currently only able to return a single object with keys as project names and values as hours: { Name1: 9, Name2: 10, Name3: 30, } What changes can I make to my code to ac ...

Exploring the array of nested objects within an array of objects

Greetings, I seem to be facing a challenge with my JSON data. My goal is to extract the "tag" value from the objects within the "cows" array. Delving into nested data structures is somewhat new to me, and I've hit a roadblock in this process. Any insi ...

What is the best way to vertically flip a background image that is repeating along the y axis in CSS?

I am in the process of developing a mobile web app and I need assistance with flipping the background image when it repeats along the y-axis. Can someone guide me on how to achieve this using CSS or JavaScript? https://i.stack.imgur.com/b107V.jpg var el ...

Why does the Formik form only validate after the second button click in this React Hooks, TypeScript, Formik, NextJS setup?

Looking for fresh perspectives on my code. The issue lies in the fact that it takes two submission attempts to validate the data inputted into a form successfully. It appears that the post request to Airtable happens before the validation schema, resulting ...

Refresh a different Angular Controller after submitting a POST request

Just to clarify, I am looking to dynamically reload another controller with new data after a POST request without refreshing the page. Here is my code: No issues with saving data to the database. Script var app = angular.module('userBase', []) ...

Implementing a function or template from one component into another within a Vue.js application, despite lacking a direct connection between the two components

Working on my Vue.js app, I encountered an interesting challenge: The layout of the app is simple: it consists of a header, a main view, and a navigation section at the bottom. Depending on the current page the user is on, I want to display a main action ...

I am in search of a specialized 3D camera with a unique effect

I am seeking assistance with animating a camera to replicate or closely resemble the effect seen in this demo: Any help would be greatly appreciated. ...

Having trouble retrieving the value of the second dropdown in a servlet through request.getParameter

I am facing an issue with storing the value of the second dropdown in a servlet after utilizing an ajax call in Java to populate it based on the selection made in the first dropdown. While I was able to successfully store the value of the first dropdown ...

Rendering issues arise in the app when utilizing browserHistory instead of hashHistory with React Router

I have integrated React Router into my current project in the following way: const store = Redux.createStore(bomlerApp); const App = React.createClass({ render() { return ( React.createElement('div', null, ...

My Next.js application does not display an error message when the input field is not valid

I've recently developed a currency converter application. It functions properly when a number is provided as input. However, in cases where the user enters anything other than a number or leaves the input field empty, the app fails to respond. I aim t ...

Why isn't my JSON data being transmitted accurately from the front end to the back end?

Below is the JSON data that I am working with: { "fields":[ {"name":"thom","techname":"rgom","description":"dfgkjd","type":"text"}, {"name":"thom","techname":"rgom2","description":"dfgkjd","type":"text"} ] } Upon posting this JSON to a NodeJ ...

Changing $scope does not automatically refresh the selected option when using ng-options with <select> in AngularJS

My select element is structured like this: <select ng-model="exportParam" ng-options="item as item.lib for item in allExportParams | orderBy:'lib'" class="form-control"> </select> To save its state for later display, I sto ...

Are there any NPM packages available for extracting PDF metadata?

Does anyone know of an npm module that allows me to modify the metatags such as Author and Title in PDF files? I am also open to suggestions for any open-license JavaScript library that can do this job. I came across a program called pdftk, which seems s ...

Can you help me understand how to access data from a selected option?

Is there a way to ensure that selecting black from the dropdown will trigger the reading of the src attribute? What modifications are needed in this code? $('.select').click(function() { var lalala = $(this).val(); $("#gallery .imgsx"). ...

What is the process of converting a value from an HTML form into a PHP variable?

I am looking to update the order preparation time. I have created an HTML form, but I am facing issues passing it into a PHP variable after this code block. I have tried using Cookies and POST method, but neither has helped me so far. <form> ...