Arun
Arun

Reputation: 89

How to extract multiple json values from a Json response

I am trying to extract multiple values from a JSON response on my jmeter script. Below is sample of my response:

{ "startDate": "2018-12-10T15:36:34.400+0000", "userId": "7211111-2fa90", "createdBy": "TEST", "note": { "content": "Application Submitted " }, "Type": "SUBMITTED" },

    "currentEventState": "CLOSED",
     {
        "Xxxx": "test",
        "Loc": null,
        "Zipcode": [],
        "Locality": 82,
        "Address": {
            "Add": 12302,
            "Add2": "place",
            "Zip": {
                "Phone": "home",
                "Email": "[email protected]"
            }
        },
        "state": "MD",
        "Cost": "E  "
    },
    "AppID": "cd8d98e6-c2a79",
    "Status": "CLOSED",

}

I am trying to extract userid and AppID for the case if the TYPE is Submitted and Status is Closed.I tried using the Json extractor with $.[?(@.Type=="SUBMITTED")].[*].?(@.Status=="CLOSED").userid,APPID, but couldn't get the expected result. Could anyone guide me on this.

Upvotes: 0

Views: 3614

Answers (1)

Dmitri T
Dmitri T

Reputation: 168217

You need to use an inline predicate to combine 2 clausees and a semicolon in order to store results into 2 separate JMeter Variables.

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

    • Names of created variables: userid;appid
    • JSON Path Expressions: $..[?(@.Type=='SUBMITTED' && @.Status == 'CLOSED')].userId; $..[?(@.Type=='SUBMITTED' && @.Status == 'CLOSED')].AppID
    • Default values: NA;NA

Here is the demo of single expression working fine:

enter image description here

And here are extracted values reported by the Debug Sampler:

enter image description here

Upvotes: 1

Related Questions