Conditional JSON execution

Hello,

I am trying to write gatling script that will send request if a element in json tuple matches specific keyword. DoIf doesn’t seem to work for this case. Following is JSON structure and thing that I am trying to achieve:

{
“id”: “”,
“title”: “”,
“description”: “”,
“categories”: [
{
“id”: “Category_Id_1”,
“title”: “Category_Title_1”,
“description”: “”
},
{
“id”: “Category_Id_2”,
“title”: “Category_Title_2”,
“description”: “”
},

and so on.

I am trying to match a specific Category Title from above JSON say “Category_Title_2” and then want to use “Category_Id_2” to form next request to be sent. Unable to do this using doIf.

Thanks in advance any help.

Sameer

This is what I am trying:

.check(jsonPath("$.categories[*].[?(@.title==category_title_2)].id").saveAs(“title_id_2”)))

सोमवार, 1 दिसम्बर 2014 5:17:54 pm UTC+5:30 को, Sameer Mainkar ने लिखा:

title is a String, to the value it’s compared to should be one too.
@.title==‘category_title_2’ // ← quotes!

Tried that out but getting following error:

findAll.exists failed, could not extract: could not extract : string matching regex [$_\p{L}][$_\-\d\p{L}]*' expected but [’ found

सोमवार, 1 दिसम्बर 2014 6:20:42 pm UTC+5:30 को, Stéphane Landelle ने लिखा:

Works for me (tested on master) as soon as I use the proper CASE: ‘Category_Title_2’

Sorry, I didn’t test properly. Investigating.

$.categories[?(@.title == ‘Category_Title_2’)].id

Thanks Stephen, its working. 2nd eye helps, should have spotted those changes earlier.

सोमवार, 1 दिसम्बर 2014 11:31:09 pm UTC+5:30 को, Stéphane Landelle ने लिखा:

No pro, have fun!