Stack Exchange
JMETER Saving userIds in an array after JSon Extraction | within a Loop Controller
I'm trying to save extracted ids (with JSON Extractor) in an array of object.
Example of response :
  {
  "password": "galderma2022*",
  "userName": "5n",
  "firstName": "ykyrlkyfao",
  "userId": "qxoql",
}

For that I used JSR223 PostProcessor
Parameters= vars.get('UserIDs') ?:  []  

if (Parameters ) {Parameters= new   
groovy.json.JsonSlurper().parseText(Parameters)}  

Parameters.add( "{'userId' : ${
new groovy.json.JsonSlurper().parse(prev.getResponseData()).userId} }")  

vars.put('UserIDs', 
new groovy.json.JsonBuilder(Parameters).prettyPrint())  

log.info("ids" + Parameters)  

log.info("UserIDs" + vars.get('param'))  

The array of object will be used in another HTTP sampler.
enter image description here
I wanted the Array to contain objects
But it was like this
[
    "{userId : 759 }",
    "{userId : 757 }",
    "{userId : 758 }"
]



Don't post code as images
We're not able to help you without seeing your full (or at least partial) response data and the desired JMeter Variable format

In the time being I can only share a couple of generic references:

Apache Groovy - Parsing and Producing JSON
Apache Groovy: What Is Groovy Used For?


So for those that have the same problem, I found a solution :
def jsonSlurper = new groovy.json.JsonSlurper()
def ids= vars.getObject('UserIDs') ?:  []
if (ids ) {ids= new groovy.json.JsonSlurper().parseText(ids)}
def object = {"userId" new groovy.json.JsonSlurper().parse(prev.getResponseData()).userId}
ids.add(object)
vars.put('UserIDs', new groovy.json.JsonBuilder(ids).toPrettyString())

