Correlating JSON Response Body in JMeter - json

I tried to design a test script of API Load Testing in JMeter 5.0. Here is my thread group info:
Below is the Body Data, I already added some variables and functions to it. You can also view the sample JSON Body Data at here:
{
"app_name": "Telekom",
"source": "MOENGAGE",
"moe_request_id": "req_${__threadNum}",
"events": [
{
"event_name": "Email Opened",
"event_code": "MOE_EMAIL_OPEN",
"event_uuid": "${__UUID}",
"event_time": ${__jexl3(${__time(,)}/1000,)},
"event_type": "CAMPAIGN_EVENT",
"event_source": "MOENGAGE",
"uid": "${__counter(,)}-${__RandomString(7,ABCDEFG123456)}${uid}",
"email_id": "${email}",
"event_attributes": {
"campaign_id": "${__RandomString(24,abcdefghijklmn123456789)}",
"campaign_name": "July2021_16072021_LigaSuper_English",
"campaign_type": "GENERAL",
"campaign_channel": "EMAIL",
"moe_delivery_type": "One Time",
"moe_campaign_tags": [
"engagement"
],
"moe_campaign_channel": "Email",
"u_em": "${email}"
},
"user_attributes": {
"PRODUCT_TYPE": "Unifi",
"moengage_user_id": "60dc48d4d722040a2e78b788",
"SERVICE_NO": "${uid}",
"id": "${email}"
},
"device_attributes": {}
}
]
}
I also include JSON Extractor to do correlation on the response body:
Here is the results in View Results Tree. Added Debug Sampler to see the whether my parameterization and correlation working or not. Fortunately, only my parameterization is working, while correlation is not.
Updated: This is example of response body:
I want to correlate at "rqUuid": "urn:uuid:1a5d8617-258c-49f7-b1a7-5b8ee71fb9fd" in the response body. Question is, is this the correct way to correlate the JSON Body? Do I need to correlate the response body although I already define the function "event_uuid": "${__UUID}" in the Body Data?
Thanks. Appreciate your help.

You are using a regular expression to get your data from a JSON response using the JSON Extractor. You need to use JSON Path Expressions instead of using regular expressions.
If you want to extract event_uuid from the response, your json path expressions would be events[*].event_uuid
To get the first event_uuid of your events array objects, you can use
events[0].event_uuid

JSON Extractor allows you executing JsonPath queries and it looks like you're trying to use a regular expression there, it will result into a syntax error, you can see jmeter.log file for details:
You're showing us request data and asking about extracting values from the response, in order to be able to help we need to see at least partial (or better full) response data and what part of it do you need.
So far I can only give the following piece of advice: switch to Regular Expression Extractor and there is a chance it will start working without any changes

You can use JSON Extractor or JSON JMESPath Extractor for extracting values from JSON responses.
Your JSON path expression should be responseHeader.rqUuid
You can evaluate the JSON Path expressions or JMESPath expression through the View Result tree or with online tools.
View Result Tree
You can generate the expressions online with http://jsonselector.com/
JMSE Path Evaluator https://jmespath.org
Sample JMX is uploaded to GitHub for your reference https://github.com/pragmatictesters/Pragmatic-Learning-JMeter-Examples/blob/master/TestPlan-StackOverFlow-68706730-JSON.jmx

Related

In Power Automate Parse JSON step I get the errors "missing required properties"

I am working on a Power Automate flow to get a JSON file from SharePoint and Parse it. On one of my previous questions I received a solution that worked with a testing JSON file. However when I ran a couple of tests with some JSON files that I need to use, the Parse JSON step gives out errors regarding "missing" required properties.
Basically, the JSON file's arrays do not always have exactly the same elements (properties). For example (below) the element "minimun_version" does not always appear under the element "link", like the image below
and because of this syntax I get the errors below
How can I Parse such a JSON file successfully?
Any idea or suggestion will help me get unstuck.
Thank you
You can allow null values in your Parse Json schema by simply adding that to the schema. April Dunnam has a nice article about this approach:
https://www.sharepointsiren.com/2018/10/flow-parse-json-null-error-fix/
I assume you have something like below in your schema?
"minimum_version": {
"type": "number"
}
You can change that to this to allow null values
"minimum_version": {
"type": [
"number",
"null"
]
}

Remove/Replace Characters in parsed JSON-output in Azure Logic Apps

Bonjour!
Is there a function for removing/replacing all of a specific character in a JSON in Azure Logic Apps?
I am working with a HTTP request in Azure Logic Apps. The results I would like to see is a unnested JSON as a CSV-file.
My steps looks like this:
1.HTTP GET ->
2.Parse JSON ->
3.CSV-file
The parsed JSON contains alot of nested values which I would like to transform to columns instead.
My idea is to delete the "{" and "}" characters from the JSON before handling it as a CSV-file which I hope will result in success.
A small example of the structure:
"data": [
"consumption_stats": {
"energy": {
"hour": {
"count": 27745,
So my question is: how can I, in Azure Logic Apps, remove/replace these characters before I make it to an CSV-file?
Thank you
There is a replace function built into Logic Apps. You could simply replace the characters with an empty string?
Click "Add Dynamic Content" then go to the expression tree and type "Replace".

Regex to get a field of Json

I have a JSON text which is returned by an API. I need to grab the value of "id" field so I can use it in a test (I am doing a corrolate test in JMeter).
I can try and find the "id": text however I cannot get the Z3G2D93 part.
Regex:
/"id":"(.+?)"/g
JSON :
{
"req":{
"dat":{
"bt":"",
"ot":"07-Apr 08:21",
"typ":"PickUp",
"tot":"3480",
"ast":"",
"an":"Test Test",
"id":"Z3G2D93"
}
}
}
Configure Regular Expression Extractor as follows:
Reference Name: anything meaningful, i.e. id
Regular Expression: "id":"(.+?)"
Template: $1$
By the way, you can test your Regular Expressions in JMeter right in View Results Tree listener using RegExp Tester mode like:
See How to debug your Apache JMeter script article for more information on how to get to the bottom of JMeter script failure.
By the way, it might be easier to deal with JSON responses using JSON Path Extractor available via JMeter Plugins

Jmeter - get nested Json string

I'm using Jmeter for API test. in one of the responses I get Json that includes the same key ("id") twice - nested and not.
this is an example of the response (part of it):
{
"id": "3600f05a-2ef6-490d-95af-7742f652cbfd",
"progress": 1,
"status": "done",
"task_update_time": "2016-01-24T08:23:12.274Z",
"result": {
"id": "c8b1ed07-0b57-4473-a4d7-08f7b829aad7",
"name": "testPrintFlow",
"geom": {
now, I want to get the second (nested) "id". until now I used Regular expression extractor. I can use it also in this case, like this:
"result":{"id":"(.+?)"
but I want something more robust. I guess I can use some Json library, but I made few tries and there seem to be many holes. can someone please recommend (and explain) what is the best way? either regular expression or Json. Thanks.

Need to extract JSON data from a JMeter response?

In JMeter, I need to extract some fields (City, Classification, and Chain) from a JSON response:
{
"StoreCode": "111243",
"StoreName": "Spencer - Sec 14 Gurgaon",
"Address1": "Gurgaon-Sector-14",
"Address2": "NCR",
"Pin": "110000",
"City": "NCR",
"Classification": "Vol 4",
"Chain": "Spencers",
"Version": "20281",
"VisitType": "Weekly"
}
Can it be done using the regular expression extractor? Is there another option?
If this piece of JSON is the all the response - it makes sense to use Regular Expression Extractor.
If you receive larger or more complicated structure - it's better to use special JSON Path Extractor available through plugin. JSON Path expressions for your JSON response would be something like $.City, $.Chain, etc.
See "Parsing JSON" chapter of Using the XPath Extractor in JMeter guide for more details on JSON Path language and on how to install the plugin.
Very easy with the plugin mentioned. See this for example. Here is link to plugin.
My biggest thing to understand was the flow. In your jmeter test you need to have an httprequest that returns data (in this case json data). So running your test you'd see json in the Response Data tab if you have a View Results Tree listener going. If you have this right click on the HttpRequest you want data from. ADD => Post Processors => jp#gc - JSON Path Extractor. Inside that extractor, you can name it anything you want.
The variable name should be one you already have defined in a User Defined Variables config element. The JSON Path would start with a dollar sign, then a dot, then the name of the key you want the value for from your json. So for me: $.logId the value from ... "logId": 4, ... in my json. It will store the number 4 in my userdefined variable. The default value can be set to something you'd never see like -1 or null or false etc...
BTW you reference your variable in your tests with ${variablename}. If putting into json and its a string do "${variablename}". Hope it helps.
Lots of the way to find out with the help of regular expression. Sharing one of them.
"City": "(.*)",
"Classification": "(.*)",
"Chain": "(.*)",