Building json path expression - presence of DOT in attribute name - json

We are working with a legacy system which gives json responses. We trying to test these json endpoints with jmeter. So, we are trying to use the json path extractor plugin for the purpose. But the structure of the json path is causing an issue in creating json path expressions.
The structure of the json which we are receiving from the server is as follows.
{
"ns9.Shopping": {
"transactionID": "XXXXXNEKIHJO7SRHN1",
"transactionStatus": "Success",
"ns9.shoppingResponseIDs": {
"ns9.owner": "1P",
"ns9.responseId": "abcdefghijklmnop"
},
"ns9.offersGroup": {"ns9.thanksGiving": [
{
"ns9.owner": "DL",
"ns9.retailOffer": [
{
"ns9.offerId": "offer1DL",
"ns9.price": 2639.08,
"ns9.currencyCode": "USD",
"ns9.taxTotal": 961.08,
"ns9.taxCode": "USD",
.........
The presence of . [DOT] in the attribute name is causing issues in my json path expression.
In short, can some one help in finding the "transactionID" from "ns9.Shopping"?

You can try to add Regular Expression Extractor within your HTTP Request element.
Put this regex:
"transactionID": "([a-zA-Z0-9]*)"
I hope this will help you.

Related

Regex for JMeter JSON Extractor

I'm using JMeter to validate some HTTPS requests, and for that, I'm using one JSON extractor and I want to extract data from the JSON response I'm getting. So from the below payload, I want to extract oper_state from any resource where service_name is equal to "Japan-1-3-12_service".
{
"resource":[
{
"id":"de04c6b1-a5a3-11ec-a02b-765e38f104a5-19",
"name":"Tokyo-1-1-10",
"service_name":"Tokyo-1-1-10_service",
"oper_state":"UP",
"type":"admin"
},
{
"id":"me05c6b1-a903-11ec-a02b-764313f104a5-19",
"name":"Japan-1-3-12",
"service_name":"Japan-1-3-12_service",
"oper_state":"UP",
"type":"admin"
},
{
"id":"5e04c691-a5a3-11ec-a02b-765e38f3q4a5-19",
"name":"France-1-1-3",
"service_name":"France-1-1-3_service",
"oper_state":"DOWN",
"type":"admin"
}
]}
I was using "$.resource[?(#.service_name=="Japan-1-3-12_service")].operational_state", but not getting any output in the variable.
Why you're using operational_state when in your JSON response it's oper_state everywhere?
Just change your JSON Path query to
$.resource[?(#.service_name=="Japan-1-3-12_service")].oper_state
and it should start working as expected
More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

Jmeter Json Extractor: JSONPath Expression works on evaluators but not inside jmeter?

I'm facing issue with a jsonpath to extract element from json.
Here is an example of the json:
[
{
"idA":"104",
"idB":"2941",
"idC":"13316",
"idE":"13361",
"idF":"12758",
"idG":"12865",
"idH":[
]
},
{
"idA":"104",
"idB":"2941",
"idC":"13317",
"idE":"13362",
"idF":"12759",
"idG":"12866",
"idH":[
"10391"
]
},
{
"idA":"104",
"idB":"2941",
"idC":"13318",
"idE":"13363",
"idF":"12760",
"idG":"12867",
"idH":[
]
}
]
Here is the jsonpath:
$[?(#.idH[0]!=null)]
The goal is to get the element where idH is not null.
It works on few json online evaluators from whom I get what I expected:
[
{
"idA": "104",
"idB": "2941",
"idC": "13317",
"idE": "13362",
"idF": "12759",
"idG": "12866",
"idH": [
"10391"
]
}
]
But it fails on others few online evaluators too, returning for example "An error occurred with JSONPath."
Unfortunately, it doesn't work with Json extractor in Jmeter, because I get the first element of the json, like if the jsonpath would have been $[0]
Any Idea what is the problem here?
Thanks in advance for any help, clue or idea.
For information in case, I use Apache JMeter (5.3)
How about using JSON Extractor which allows executing arbitrary JsonPath queries
You should be able to get the object you're looking for as simple as:
$..[?(#.idH[0])]
Demo:
More information: API Testing With JMeter and the JSON Extractor

How to parse dynamic json reponse and get specific value and pass it as an input to next request

I get .json file as a response from an API and from that file I should parse and fins specific parameter and pass it as an input to the next request, how do I do that using Katalon.
If I say
response = JSON.parse("response.json");
it says it is unable to identify JSON as valid. Can someone help me out with the solution?
Your JSON is invalid, maybe it is a copy-paste issue.
The valid JSON should be
{
"responseStatusCode": "OK",
"data": {
"screenName": "employeeTimeslip",
"screenType": "Redirect",
"searchResultCount": 0,
"rows": [],
"tabs": [],
"searchParams": {
"employeeID": "000092926",
"timeslipNumber": "201900019701"
}
}
}
So, you were missing a "," between "OK" and "data" and two closing curly braces at the end of the file.
You can check JSON files for validity yourself using online JSON validators, for example, this one.
i found a way to read specific parameter from the json response file like below:
val scn = scenario("ClaimSubmission")
.exec(http("request_2")
.post("URL")
.headers(headers_2)
.body(RawFileBody("json file path"))
.check(jsonPath("$..timeslipnumber").find.saveAs("timeslipnumber")))
Timeslip number would be retrieved using : .check(jsonPath("$..timeslipnumber").find.saveAs("timeslipnumber")))

How to create html table from blob json in Azure Logic App

Hi I would like to create html tabe in Azure Logic App.
I have data loaded from blob via Blob connector (Get blob content using path)
I used Compose connector based on answer in this post
But I get error -
Unable to process template language expressions in action 'Create_HTML_table' inputs at line '1' and column '1747': 'The template language function 'json' parameter is not valid. The provided value '[{"ServiceName":"routingsf","SubServiceName":"roadinfo/supportedmaps","ErrorType":"System.AggregateException","ErrorMessage":"One or more errors occurred. (Object reference not set to an instance of an object.)","Count":4} ]' cannot be parsed: 'Unexpected character encountered while parsing value: . Path '', line 0, position 0.'. Please see https://aka.ms/logicexpressions#json for usage details.'.
Code of Compose and Create HTML table connector is like :
"Compose": {
"inputs": "#base64ToString(body('Get_blob_content_using_path').$content)",
"runAfter": {
"Get_blob_content_using_path_2": [
"Succeeded"
]
},
"type": "Compose"
},
"Create_HTML_table": {
"inputs": {
"format": "HTML",
"from": "#json(outputs('Compose'))"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "Table"
},
Can you help?
Maybe you could try my way to create table. After get the content, use the Parse JSON , the content input json(body('Get_blob_content_using_path')), the Scheme choose Use sample payload to generate schema and just copy and paste your json file content.
Then create HTML table , the From choose the expression array(body('Parse_JSON')).
Here is the Logic flow and my result.
Hope this could help you, if you still have other questions, please let me know.
Update: I copy your json content tomy json file and test again. And It works.
So please make sure you logic app flow is right. Or you could share you flow.
Make sure these two steps are right:

How to escape \r\n in the body of a POST in JMeter

I have a JSON response as follows,
{
"name":"John Smith",
"address": "#123\r\nRenault Road\r\n123456\r\n"
}
and I need to extract the address and put it into my next POST request. I use the JSON Extractor as a post processing element and with $..address I set the extracted address to the variable address.
In my next request, I use the following as the POST data,
{
"id": "123456",
"address": "${address}"
}
So when I make the request I see the POST data as,
{
"id": "123456",
"address": "#123
Renault Road
123456
"
}
This breaks at my backend and nevertheless this payload is not identified as a valid JSON as well.
I want to make the request so that the POST data is as follow,
{
"id": "123456",
"address": "#123\r\nRenault Road\r\n123456\r\n"
}
Any help to get this done is highly appreciated.
If you really need to send these line breaks as \r\n you can use some scripting to convert them back.
Add Beanshell PreProcessor as a child of the "next request" HTTP Request Sampler
Put the following code into the PreProcessor's "Script" area:
address = vars.get("address");
address = address.replaceAll("\\r\\n","\\\\r\\\\n");
vars.put("address", address);
The above script will convert line breaks to the textual representation.
References:
vars is a shorthand for JMeterVariables class instance, it provides read/write access to all JMeter Variables
String.replaceAll() - is the method of String class which comes out of box with Java SDK
How to Use BeanShell: JMeter's Favorite Built-in Component - guide demonstrating how to use Java and JMeter APIs using Beanshell test elements to enhance your JMeter tests with scripting if required