Reputation: 311
Im using the following JSON and query to calculate the array length in the JMeter json extractor.
{ "data": { "modal": "HJ", "technicalid": "e492fc62-a886-67a461b76de8", "viewModel": { "series": [ { "name": "H_0_G_0_R_0", "UID": "J_0_G_0_R_0", "description": "Test1", "type": "series", "groups": [ { "name": "H_0_G_0", "UID": "G_0_G_0", "description": "Group 1", "type": "group" } ], "postProcessing": null } ] }, "status": "success" }, "success": true, "statusCode": 200, "errorMessage": "" }
Here is the query.
data.Model.series[0].groups.length
This is working fine in the online jsonquerytool. When I use this query in the JMeter json extractor, it is returning null. I assume this is because it is returning an integer because other similar queries which are returning strings are working fine with json extractor . How to find the array length in JMeter json extractor?
Upvotes: 0
Views: 3670
Reputation: 168092
With JSON Extractor you can provide "Match No." as -1
:
and the number of matches will be available as foo_matchNr
JMeter Variable:
Alternative option is going for JSON JMESPath Extractor which provides length()
function so you can get the size of the array as:
length(data.viewModel.series[0].groups)
or if you prefer pipe expressions
data.viewModel.series[0].groups | length(@)
Upvotes: 2
Reputation: 2074
Why JSON extractor to calculate the length? You could use a post processer. Like JSR223 post processer using groovy script.
import groovy.json.*
def response = prev.responseDataAsString ;
def json = new JsonSlurper().parseText(response) ;
def sizeResultPractitioners = json.data.viewModel.series[0].groups.size();
log.info("---------->"+sizeResultPractitioners);
I tried with your JSON response payload and also tried with modified response payload,
With modified response payload,
Upvotes: 1