ATLANTBH / jmeter-components

Apache jMeter components
Apache License 2.0
78 stars 51 forks source link

Extract data from json response #13

Closed nehabansal14 closed 7 years ago

nehabansal14 commented 7 years ago

I have this json response: { "total":1, "page":1, "records":23, "rows": [ { "id":409587, "from_status":"[Default Status]", "to_status":"New", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409582, "from_status":"Approved", "to_status":"Done", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409583, "from_status":"Approved", "to_status":"In Process", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409584, "from_status":"Closed", "to_status":"Done", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409585, "from_status":"Closed", "to_status":"Rejected", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409586, "from_status":"Closed", "to_status":"Reopen", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409588, "from_status":"Deferred", "to_status":"Rejected", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409589, "from_status":"Deferred", "to_status":"Reopen", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409590, "from_status":"Done", "to_status":"Closed", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409591, "from_status":"Done", "to_status":"Rejected", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409592, "from_status":"Done", "to_status":"Reopen", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409593, "from_status":"In Process", "to_status":"Done", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409594, "from_status":"In Process", "to_status":"Wait for Review", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409595, "from_status":"New", "to_status":"Approved", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409596, "from_status":"New", "to_status":"Deferred", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409597, "from_status":"New", "to_status":"Done", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409598, "from_status":"New", "to_status":"In Process", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409599, "from_status":"New", "to_status":"Rejected", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409600, "from_status":"Rejected", "to_status":"Reopen", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409601, "from_status":"Reopen", "to_status":"Done", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409602, "from_status":"Reopen", "to_status":"In Process", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409603, "from_status":"Wait for Review", "to_status":"Approved", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" }, { "id":409604, "from_status":"Wait for Review", "to_status":"Reopen", "transition_name":"", "assign_id":"7", "exclude_groups_value":"" } ] }

and i Want to extract id where from_status=new and to_status=in process. I have tried this $..[?(@.from_status == 'New')] its giving me: CreatorData_1={id=409595, from_status=New, to_status=Approved, transition_name=, assign_id=7, exclude_groups_value=} CreatorData_2={id=409596, from_status=New, to_status=Deferred, transition_name=, assign_id=7, exclude_groups_value=} CreatorData_3={id=409597, from_status=New, to_status=Done, transition_name=, assign_id=7, exclude_groups_value=} CreatorData_4={id=409598, from_status=New, to_status=In Process, transition_name=, assign_id=7, exclude_groups_value=} CreatorData_5={id=409599, from_status=New, to_status=Rejected, transition_name=, assign_id=7, exclude_groups_value=} these values.

now i need to extract id where to status is in process.

I have used this http://screencast.com/t/hk0Zzj0fHLQ used regular expression and select jmeter variable.

now its taking value but its a dynamic json and it can change anytime. for now CreatorData_4 having my value but in future may be it will not display. then for this what shall i do?

tarikdem commented 7 years ago

Maybe the json path extractor would be a better choice in this case? You can use it with logical operators '||' (OR) and '&&' (AND) for matching multiple values.

This would be the needed matcher with the json path extractor:

$.rows[?(@.from_status == 'New' && @.to_status == 'In Process')]