0

JSON response is returned in the following format, I need to extract values from the first index of the array for example 925,88 using groovy or perhaps another language, and then store them into a variable to pass them along in the next request. Also, values need to be unique

[
    [
        22588,
        [
            925,
            88
        ],
        0,
        0,
        0,
        null,
        "moderate"
   ]

Any help would be appreciated!

Thanks

daggett
  • 26,404
  • 3
  • 40
  • 56

1 Answers1

0
  1. Add JSR223 PostProcessor after the JSON Extractor

  2. Put the following code into "Script" area:

    def numbers = []
    
    1.upto(vars.get('foo_matchNr') as int, { index ->
        new groovy.json.JsonSlurper().parseText(vars.get('foo_' + index)).each { number ->
            numbers.add(number)
        }
    })
    
    vars.put('payload', new groovy.json.JsonBuilder(numbers.sort().unique()).toPrettyString())
    
  3. Replace foo with the actual JMeter Variable name you use in the JSON Extractor

  4. Use ${payload} where you need to send unique numbers

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • never mind, the issue was with the way I was extracting the JSON response, the solution you provided is working now. Thanks a ton! :) – Shavaiz Safdar Jan 05 '22 at 14:51