JMeter JSON Path Extractor expression issue while searching arrays - json

My HTTP request returns an array similar to
[
{"id":"1", "data":"abc"},
{"id":"2", "data":"def"},
{"id":"3", "data":"ghi"}
]
As an input for a ForEach Controller I'm trying to extract the ids of above result into an array using a JSON Path Extractor with a Path expression of $..id.
I'm expecting to get something similar to ["1", "2","3"] but the output I get is
ids=3
ids_matchNr=3
It appears that the JSON Path Extractor only matches/extracts the last occurrence of id instead of collecting all occurrences of the id values and adding them to an aray.
The same expression and data return the expected ["1", "2","3"] result array in jsonpath.curiousconcept.com so the expression seems to be correct.
Am I doing something wrong or is this a bug in the JSON Path Extractor?
Below are some screen prints for a little test

I cannot reproduce your issue:
JSON Extractor
JSON Path Extractor
So double check you are using the latest version of JMeter and JSON Path Extractor, the latter one can be upgraded using JMeter Plugins Manager

Related

Need to extract a josn value for nested requests in JMeter using Jsonpath extractor

I have response which derived from a action. I need to extract a value of userid node using json path extractor in JMeter
{
"ABC": "{"response":{"userId":user1,"caseId":0,"name":"Json","email":"json#xyz.com","mobileNumber":"1223456789","countryCodeId":"1","countryCode":"+90","emailOTP":830782,"mobileOTP":301879,"mobileOTPString":null,"otpCreationDate":"2021-10-14T10:01:38.5802765Z","configOTPTimeOut":120,"redirectUrl":null,"isOTPExpired":false,"countryCodeValidMessage":null,"mobileNumberValidMessage":null,"offset":"00:00:00","postStatus":false,"postMessage":null,"id":null,"response":null,"isProceedToCreateMeeting":false},"successcode":0,"message":null}"
}
I have tried $..ABC.response.userId, it says NoMatch. what is the correct syntax to extract userId node which is present inside response
What you're showing us is not a valid JSON (you can check it yourself using i.e. https://jsonlint.com/ website or equivalent) therefore you won't be able use either JSON Extractor or JSON JMESPath Extractor
Unless it's a copy-paste issue you're limited to Regular Expression Extractor, example regular expression would be something like:
"userId"\s*:\s*(.+?)\s*,

Jmeter Json Extractor multiple conditions

I want to extract the value of id where Principals.value.type='USER', but my json has multiple 'id' tags. i wish to extract the first one.
Note: there can be multiple jsons in the response
Example json:
{"content":[{"id":"210A3A-0135-1036-90B8-0A2163","name":"xyy 927","description":"xyz Description","policy_set":"xyz2","offline_lease_period":{"value":102,"constraint":"NOT_CHANGEABLE"},"is_tracked":{"value":true,"constraint":"NOT_CHANGEABLE"},"validity_period":{"value":{"days":195,"type":"Relative"},"constraint":"NOT_CHANGEABLE"},"principals":{"value":[{"common_name":"xyz#gmail.com","id":"8B5F4-96C2-1035-8AB7-0A2163","domain":"APRM Domain","role":"DEFAULT","email":"abc#gmail.com","updated":"2017-11-02T04:54:49.272Z","created":"2017-11-02T04:54:49.272Z","type":"USER"}],"constraint":"NOT_CHANGEABLE"},"permissions":{"value":[],"constraint":"NOT_CHANGEABLE"},"watermark_id":{"value":"","constraint":"NOT_CHANGEABLE"},"policy_type":"NON_CUSTOMIZABLE","created":"2018-03-09T04:41:31.277Z","updated":"2018-03-09T04:41:31.386Z"}
First of all your json is returning the error
Parse error on line 1:
...3-09T04:41:31.386Z"}
-----------------------^
Expecting ',', ']', got 'EOF'
if you are able to get the Id Tag using Json Extractor Then you can use variable name _Count for example
The relevant JSON Path query would be something like:
$..principals.value[?(#.type == 'USER')].id
If you want the first id you can just set "Match no" to 1 in the JSON Extractor
References:
JSON Path: Filter Operations
JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

How to Extract value from Json Path Post Processor?

I need to extract id where asOf : 2016-11 for latest run.
e.g given below response of request I need to store 21aa83fe-fe1b-4447-9b2e-05e7d6cd67d3 in a variable because as of 2016 is in the last and-and the corresponding id is. Could you please tell me how to write JSON Path Post Processor Expression out of it?
{"id":"1fabbb02-0b7d-4bec-badd-9fe9f1c63f08","batch" {"id":"GL1600"},"asOf":"2014-06-16T00:00:00Z","version":3,"statusIdentifier":"END"},
{"id":"212fc2b5-03d6-4d76-ab6d-e9e783459120","batch":{"id":"N1400"},"asOf":"2014-06-16T00:00:00Z","version":3,"statusIdentifier":"END"},
{"id":"21aa83fe-fe1b-4447-9b2e-05e7d6cd67d3","batch":{"id":"N1500"},"asOf":"2016-11-16T00:00:00Z","version":3,"statusIdentifier":"END"},
If your response is valid JSON you can use == filter operator like
$..[?(#.asOf == '2016-11-16T00:00:00Z')].id
References:
JSON Path - Filter Operators
Advanced Usage of the JSON Path Extractor in JMeter
If response is not valid JSON you will need to go for Regular Expression Extractor instead.

How to parse json array into string for use as parameters later in jmeter?

Sample input as below:
[{"program":"C:/temp/abc.exe","actions":"9","file_name":"abc1","new_file_name":"newabc1","version":"2.0.0.0","product_name":"abc","description":"abc","eventdate":"20160601120000"},{"program":"C:/temp/abc.exe","actions":"9","file_name":"abc2","new_file_name":"newabc2","version":"2.0.0.0","product_name":"abc","description":"abc","eventdate":"20160601120000"}]
I need to parse this json array into string for use in the following http request as parameters. I new to jmeter and tried to follow the example in http://theworkaholic.blogspot.my/2012/05/json-in-jmeter.html but i can't seem to get the value of jsonResponse at last.
[UPDATE]
[]1
Your question is not clear enough, however here are some clues:
If you need to store the whole response into a JMeter Variable for later re-use - go for Regular Expression Extractor configured as follows:
Reference Name: anythingMeaningful, i.e. jsonResponse
Regular Expression: (?s)(^.*)
Template: $1$
If you need 2 separate JSON Objects from the array - JSON Path PostProcessor is available since JMeter 3.0
$.[0] - for 1st JSON Array item
$.[1] - for 2nd JSON Array item
If you need anything else - use the same JSON Path PostProcessor. I would recommend getting familiarized with the following material:
JSONPath - XPath for JSON
Advanced Usage of the JSON Path Extractor in JMeter
Still no luck - update your question with exact details on how you need to re-use that JSON data in next request(s)

ATLANTBH jmeter-components: JSON Path Assertion

I'm trying to perform a JSON assertion using ATLANTBH jmeter JSON PATH Assertion. However I cant seem to write a correct expression to get the following fields from the JSON feed posted below:
123456789
1009
SOME RANDOM MESSAGE
{"api": {"status":"Success","callsremaining":36,"version":"x.x.x.x"}
,"result":{"errors":{"123456789":{"code":1009,"error":"SOME RANDOM MESSAGE"}}}
}
Has anyone here got any experience using this JMeter plugin?
I know I could use regex and Beanshell to validate but I'd rather use these JSON Path Assertion.
Any help you could provide would be most appreciated.
Looks like you can easily assert both 1009 and SOME RANDOM MESSAGE values using JSONPath expressions (in JSON Path Assertion components) but not sure about 123456789: that's not node value but bode name, and JSONPath implementation used by these components seems has no expressions to get node name.
Suppose you can easily use to assert 123456789 instead binding of JSON Path Extractor (from the same components collection) with jmeter's standard Response_Assertion.
Add 2 JSON Path Assertions as children to the sampler which returns json response you want to process:
Expressions will be $.result.errors..code and $.result.errors..error correspondingly.
Add JSON Path Extractor as child to the same sampler to extract full error entry:
Expression: $.result.errors..
This will extract {"123456789":{"error":"SOME RANDOM MESSAGE","code":1009}} and save into the pointed variable (${errorKey}).
Add Response Assertion as child to the same sampler, after previously added JSON Path Extractor:
This will assert name of the key (123456789) in the value of ${errorKey} variable.
So the final construction may look like
...
YOUR Sampler
JSON Path Extractor
JSON Path Assertion
JSON Path Assertion
Response Assertion
...