0

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?

2 Answers 2

2

With JSON Extractor you can provide "Match No." as -1:

enter image description here

and the number of matches will be available as foo_matchNr JMeter Variable:

enter image description here


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(@)

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

You might want to put a .* in the JSON path expression like $.data.viewModel.series[0].groups.* for foo_matchNr to give the correct value.
1

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,

enter image description here

With modified response payload, enter image description here

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.