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

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

Related

Jmeter: Json Extractor: Response from first request to be used in next Request

I have a Http request for which i am getting data from CSV data file and i am getting a response body as {"abc":"123456123"}. I have added JSON extractor as child to this Http request. I am given variable name as abc and tried json path as both $..abc or $.abc and now i have added new Http request(2) in which i want to pass variable name from json extractor in request body(2). I have used same variable name in the http request body(2) but the variable name is not passing in the new request.
I gave all the options in json path in json extractor, i am expecting that for each response {"abc":"123456123"}(this value will change for each request) json extractor should get the response value and pass in the next request body.
When i am running the script, the value is not passed in request2.
Response of request 1 :- for single thread
{"abc":"123456123"}
Json Extractor:-
name of variable : abc
JSON path:- $.abc
Request 2:-
{
"a":{
"b":[
{
"mRID":"${abc}",
"abc":[
{
"a":[
{
"n":[
{
"na":[
{
"a":"",
"a":"AF",
"value":"add"
}
]
}
],
"cr":[
{
"name":"0071",
"nameType":"r#"
},
{
"name":89923,
"nameType":"NR#"
}
],
"CS":[
{
"dateTime":"${__timeShift(yyyy-MM-dd'T'hh:mm:ss)}",
"type":"CS",
"value":"x"
}
]
}
]
}
]
}
]
}
}
I cannot reproduce your issue using Dummy Sampler and the JSON Extractor configuration you described.
Try adding Debug Sampler after the uuu request and see if there is abc variable generated and what value does it have.
Also check jmeter.log file for any suspicious entries

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

Use result from jdbc request for the next request

I am using JDBC to query on azure sql in JMeter. I was able to successfully get the response. see below
otp
100940
In the Result variable name the value is OTP
My next step in Http request POST method, see below
{
"id": ${requestId},
"otp": "${OTP}",
"requestId": "123456"
}
as you can see otp is parameterized.
But in actual request see below;
POST data:
{
"id": 506,
"otp": "[{otp=100940}]",
"requestId": "123456"
}
how can I concatenate so that I only get the actual otp value without the [{otp=}]
You can add Regular Expression Extractor to extract number from OTP variable
Choose Apply To: JMeter Variable and write OTP and use regular expression as:
otp=(\d+)
And use Template $1$ and Match No. 1
JMeter Variable Name to use - extraction is to be applied to the contents of the named variable
If your response is this otp 100940, use below Regular Expression to extract it:
Now, you can use anywhere OTP value using ${OTP} variable
{
"id": ${requestId},
"otp": "${OTP}",
"requestId": "123456"
}

Extract JSON value based on condition using Jmeter from an HTML page

I want to extract JSON value based on condition using jmeter from an HTML page.
<!doctype html>
var list_data_obj = [{
"list": [
{
"field1": "123",
"field2": "xyz"
},
{
"field1": "456",
"field2": "abc"
},
{
"field1": "789",
"field2": "asdf"
}
],
"other1": "qwerty",
"other2": "asdfgh"
}]
</html>
have tried JSON Path Extractor as below but returned NULL.
$.list[?(#.field2 == 'abc')].field1
Thanks
You won't be able to use JSON Path Extractor as response data is not a valid JSON, it looks like a mix of HTML and JavaScript therefore you will need to use Regular Expression Extractor instead.
The relevant Regular Expression will look like:
"field1": "(.+?)",\s.*"field2": "abc"
References:
JMeter: Regular Expressions
Using RegEx (Regular Expression Extractor) With JMeter
Perl 5 Regex Cheat sheet
The key is to first extract a valid json using a regular expression, then apply a json path extractor on the previously extracted json.
You can perform a 2-step extraction to do this:
First Extract the Json from the page by performing a regexp extractor with "list": ([^^]+}\]), group $1$,
Then perform a Json Extractor on the extracted variable by selecting JMeter variable, then apply your json path $.list[?(#.field2 == 'abc')].field1.
Useful resources:
How to extract data from Json with JMeter

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