JMeter_User
JMeter_User

Reputation: 303

JSON extraction based on condition in Jmeter

I need to extract user id from the below json response. But I should only extract user id when the absent attribute is "false".

"availableUsers":[ { "userId" : 6492, "workDate" : "08 07 2020 00 00 00", "workDay" : 6, "workShortName" : "1430-2330_RCO", "workTimes" : "14:30 - 23:30", "Layer" : 4, "earliestStartTime" : null, "latestEndTime" : null, "otaEntryAllowed" : false, "isDayLocked" : false, "isDayOff" : false, "TimeType" : "Overtime", "absent" : false, "comment" : "", }, { "userId" : 6493, "workDate" : "08 07 2020 00 00 00", "workDay" : 6, "workShortName" : "1430-2330_RCO", "workTimes" : "14:30 - 23:30", "Layer" : 4, "earliestStartTime" : null, "latestEndTime" : null, "otaEntryAllowed" : false, "isDayLocked" : false, "isDayOff" : false, "TimeType" : "Overtime", "absent" : true, "comment" : "", }]

Upvotes: 0

Views: 312

Answers (1)

Dmitri T
Dmitri T

Reputation: 168217

In JsonPath there are Filter Operators therefore you can extract the userId attribute value for the "absent" users as:

$.availableUsers[?(@.absent == false)].userId

Demo:

enter image description here

More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

Upvotes: 2

Related Questions