How to identify the specific true or false value from json assertion using jmeter?

285 Views Asked by At

The requirement is we have to identify "elements" and then check if its true or false.

{
    "first": {
        "second": [
            {
                "element": 1,
                "elementrec": null,
                "enabled": true,
                "rec": null
            },
            {
               "element": 2,
                "elementrec": null,
                "enabled": false,
                "rec": null
            },
            {
                "element": 3,
                "elementrec": [
                    "3"
                ],
                "enabled": true,
                "rec": [
                    "3"
                ]
            }
        }
      ]
    } 
}

Above 3 element has either true or false. Would like to identify all 3 elements for true or false using different json assertion.

1

There are 1 best solutions below

3
Dmitri T On

I don't know what do you mean by "identify", there are too many possible options so I'll come up with the shortest one:

  1. Add JSR223 PostProcessor as a child of the request which returns the above JSON

  2. Put the following code into "Script" area

    new groovy.json.JsonSlurper().parse(prev.getResponseData()).first.second.each { item ->
        log.info('Element: ' + item.element + ', enabled: ' + item.enabled)
    }
    
  3. Run your test

  4. In jmeter.log file you will see "elements" with their "enabled" status

Demo:

enter image description here

More information: