skip to Main Content

Im new to jmeter and wanted to extract the array data from json object
i have a Json as below

{
"error": false,
"data": {
"seq": [
"71128dfa",
"cbfda925",
"9d9bfa68",
"0ca86cf2",
"8bc3cfa7",
"4ea9aee3"
],
"request_id": "1db799cf-8f2b-4982-a23e-b2fb95b609b9"
}
}

i need to get the data which is under seq array

2

Answers


  1. You can use Json Extractor to extract it

    you need to pass the json path expression to retrieve it

    enter image description here

    enter image description here

    Login or Signup to reply.
  2. Since JMeter 3.1 it’s recommended to use JSR223 Test Elements and Grooovy language for scripting so I would recommend switching to JSR223 Post-Processor

    If you want the JSON Array which lives under seq attribute you can extract it using the following code:

    def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
    
    def seq = response.data.seq
    
    vars.put('seq', new groovy.json.JsonBuilder(seq).toString())
    

    You will be able to refer the extracted value as ${seq} where required.

    Demo:

    enter image description here

    More information:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search