Neha
1
Hi,
Say I have the following json:
{
“field1”: 2,
“field2”: [
{
“foo”: “123”,
“bar”: “abc”
},
{
“foo”: “456”,
“bar”: “def”
}
]
}
and I want to save that foo value whose bar is ‘abc’, i.e I need to extract the value 123 in this example. How would I do that in gatling?
I tried referring to the examples in: http://goessner.net/articles/JsonPath/
and came up with: .check(jsonPath("$.field2[?(@bar=abc)]").saveAs(“fooArrayElement”))
to see if I could atleast extract:
{
“foo”: “123”,
“bar”: “abc”
}
and then probably further extract foo from this, but I got an error instead.
Neha
2
Also tried following, but it didn’t work:
.check(jsonPath("$[field2][?(@bar=abc)].foo").saveAs(“myFoo”))
Neha
3
Ok so I figured this out for static bar values, i.e below works for me:
.check(jsonPath("$[‘field2’][?(@. bar == ‘abc’]. foo").saveAs(“myFoo”))
however, if I try to replace ‘abc’ by a value stored in the session as a attribute e.g:
.check(jsonPath("$[‘field2’][?(@. bar == ‘${myBar}’]. foo").saveAs(“myFoo”))
it fails. Any idea how I could fix this?
Neha
4
Solved it, I was missing a ‘)’ above, it’s supposed to be:
.check(jsonPath("$[‘field2’][?(@. bar == ‘${myBar}’)]. foo").saveAs(“myFoo”))