Naseem
Naseem

Reputation: 961

How to use JSON path extractor to pick the same value for 2 condition

I have a JSON response like this

Members":
[
    {
        "id":"ABC",
        "name":"XXXX",
        "XXX":"XXX",
        "XXXX":"XXXX",
        "Managers":
        [
            {
                "id":XYZ,
                "name":"XXX",
                "XXXX":XXXX,

            }
],

I need to get the value ABC and XYZ from the above response and I am using 2 JSON extractor to fetch the value and storing it in different variable.

JSON Extractor 1 expression:-

$..Members.[*].id

JSON Extractor 2 expression:-

$.Members..Managers.[*].id

But the above code picks the value from different arrays like sometime it picks the Members id as ABC but picks the Managers ID from different array. I want it to pick the value from same array value.

Any suggestions?

Upvotes: 0

Views: 1550

Answers (1)

Dmitri T
Dmitri T

Reputation: 168157

Assuming that you need to extract first member and his first manager:

  1. Add JSON Extractor as a child of the request which returns above JSON and configure it as follows:

    • Variable names: memberId; ManagerId
    • JSON Path expressions: $.Members[0].id; $.Members[0].Managers[0].id
    • Match No: 1; 1
    • Default Values: NOT_FOUND; NOT_FOUND

      JMeter JSON Extractor

  2. Refer ABC as ${memberId} and XYZ as ${ManagerId} where required. You can see JMeter Variables using Debug Sampler and View Results Tree Listener combination

    JMeter Variables from JSON

Upvotes: 1

Related Questions