0
votes

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?

1
Use index option instead of $..Members.[*].id use $..Members.[0].id which will always use the same indexLiger
But that will ensure that all the threads are using the same value which is not the correct approach.Naseem
Please exemplify your use caseLiger

1 Answers

1
votes

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