JMeter JSON Path Extractor expression issue - jmeter

My http request returns a json similar to this:
{
"ReturnData": {
"Foo_ef49f92628083fab6e14545c547bcf38": {
"ViewId": "Foo_ef49f92628083fab6e14545c547bcf38",
"ViewName": "Foo"
},
"Bar_ef49f92628083fab6e14545c18871839": {
"ViewId": "Bar_ef49f92628083fab6e14545c18871839",
"ViewName": "Bar"
}
}
}
In JMeter I use the JSON Extractor with the following expression to find the ViewId value of the element with the ViewName Bar.
$.ReturnData[?(#.ViewName == 'Bar')].ViewId
But this isn't working, the variable is empty.
When i write something in the default values field, that value is used so the script part is correct.
I tried a few online jsonPath expression tools and all return the correct value but JMeter doesn't.
Does JMeter use some special syntax here, am i missing something or is there another way to achieve this?

Ok i found the solution.
$.ReturnData.*.[?(#.ViewName=='Bar')].ViewId
This works as expected.
Btw i found the JSON Path Tester in JMeter which helped a lot.
I still don't understand why the online tools worked but anyway, i'm happy this works now.

Related

Jmeter extracting response multiple id from array

I am traying the extract the term-id- id value -200000000326 from the below response. controlled-term can have multiple term-id, I have tried with Json extractor $..controlled-term.[[term-id]].[id] and [Thursday 12:22 PM] G, Shwetha C
$..term-id[id]
but this is returning null. can you please help
enter code here:
{
"controlled-terms": {
"controlled-term": [
{
"term-id": {
"id": "200000000326"
},
"term-names": {
"term-name": [
{
"lang": "en",
"name": "All"
}
]
}
}
]
}}
For particular that JSON you provided the relevant JSONPath query would be something like:
$.controlled-term.*.term-id.id
If you need to extract particular ID which is related to some other attribute value - you will have to provide the full JSON response and specify the data relationships.
I would also recommend considering switching to JSON JMESPath Extractor mainly because it has official specification (JSONPath implementations are lacking it so query which works for one implementation may fail for another). Moreover JMESPath language is more powerful and provides a lot of functions and operators which can make your life easier. More information: The JMeter JSON JMESPath Extractor and Assertion: A Guide

How to correlate drop down list

I have a response like below-
"distributionChannelList":[
{
"id":1,
"description":"Agency1"
},
{
"id":5,
"description":"Agency2"
},
{
"id":4,
"description":"Agency3"
},
{
"id":3,
"description":"Agency4"
}
],
"marketingTypeList":[
{
"id":1,
"description":"Type1".......
There are so many 'id' and 'description' values in my response. Agency1, Agency2.. are drop downs in my application.
So I want Jmeter to pick a different agency every time and pass in subsequent requests.
How to achieve this?
Use json extractor or reg Ex to fetch all the description with Match No. as 0 for random. Pass the Json created variable to the next request like ${varDescription}. On every run, random value will be fetched and provided to the next request.
Below snapshot is an example for regex but prefer json in your case. For fetching with json use $..description as json path expression. Repeat the same for others if required.
Hope this helps.
Update:-
Please check the below config. It will extractor 2 values in sync. But, ${cnt} should be same value. I have used counter just for demo. You can use random function to generate value between 1 to 4 and pass that variable ${rnd};${rnd}.

Google Cloud Tasks always set HttpMethod to GET when using HttpRequest as payload_type

According to this documentation [ https://cloud.google.com/tasks/docs/creating-http-target-tasks ], one should be able to create tasks with type 'http_request' and 'http_method' set to 'POST', but the behavior is not the expected once the task is always created with method 'GET'.
After having this issue while using the Python Client Library, I've decided to try the API directly and check if it was an issue with the library or with the API itself.
Using the "Try this API" from the product's documentation page [ https://cloud.google.com/tasks/docs/reference/rest/v2beta3/projects.locations.queues.tasks/create ], I've tried to create similar tasks using both http_request and app_engine_http_request types and always setting the http_method to POST.
If I set the request body like this:
{
"task": {
"appEngineHttpRequest": {
"httpMethod": "POST",
"relativeUri": "/test",
"body": "c2hhbGxvdyBub3c="
}
}
}
...the task is created and the method is POST, like expected. But, if I set the request body to:
{
"task": {
"httpRequest": {
"httpMethod": "POST",
"url": "https://httpstat.us/404",
"body": "c2hhbGxvdyBub3c="
}
}
}
...the task is created, but with method GET instead of POST.
Here's what I get at my queue:
I believe this is a bug, and that's why I'm reporting it here with tag google-apis-explorer as recommended at the support page.
Anyway, if anyone could tell me if I'm doing something wrong or if there's any workaround in the meanwhile I would really appreciate.
Thanks!
Thank You for this post, this is a bug in the existing Cloud Tasks UI and we are in the process of fixing this bug.
In the meantime the correct HTTP method of the task can be determined by running the following command:
gcloud beta tasks describe
https://cloud.google.com/sdk/gcloud/reference/beta/tasks/describe
The above command will show the correct HTTP method for the task.

I need to get the value of token id using Json path extractor instead of using Regex

I need to get the value of token id using JSON path extractor instead of using Regex
Here is the response:
{
"username":"Test",
"project_name":"Testing",
"user_domain_id":"default",
"roles":[
{
"name":"_member_"
}
],
"services_region":"regionOne",
"user_domain_name":"Default",
"enabled":true,
"domain_name":null,
"id":"9354ad0e4022423db85fa148c9876d30",
"available_services_regions":[
"regionOne"
],
"is_superuser":false,
"token":"6265e8da4807429ea65febf0a2312091",
"project_id":"5abf103686584fa09860f04d0887f181",
"domain_id":null
}
JSON Extractor is the best way to get value from JSON, in your case token is in first level child of JSON, so use the following expression:
$.token
Another way is using expression:
['token']
for more expression syntax see JSON Path
. or [] child operator

JMeter JSON Path Extractor how-to

I want to pull out href values where id : 923 using JSON extractor for Jmeter.
I tried,
$..entries[?(#.id == '923')].links[0].href
But it didn't work. How should I get the values by their id?
Here's some sample data.
"entries":[{
"id":"921",
"updated":"9999-12-31T23:59:59.999Z",
"links":[{
"href":"url1",
"rel":"related-action",
"title":"Execute related action"
},{
"href":"url2",
"rel":"icon"
}
]
},{
"id":"922",
"updated":"9999-12-31T23:59:59.999Z",
"links":[{
"href":"url3",
"rel":"related-action",
"title":"Execute action"
},{
"href":"url4",
"rel":"icon"
}
]
},{
"id":"923",
"updated":"9999-12-31T23:59:59.999Z",
"links":[{
"href":"url5",
"rel":"related-action",
"title":"Execute action"
},{
"href":"url6",
"rel":"icon"
}
]
}
]
Try removing quotation marks so your JSON Path Expression would look like:
$..entries[?(#.id == 923)].links[0].href
Your JSON is malformed, you need to surround it with {} characters in order so JSON Path Extractor could work with it.
Try updating Extras with Libs set plugin to the latest version - 1.3.0 as for the moment.
References:
JSON Path Syntax
Parsing JSON

Resources