Reputation: 21
I run a request in Jmeter which response looks something like this:
{
"Items":[
{
"Available":3,
"Info":[
{
"Sample1":1,
"Sample2":33,
"Sample3":50,
"Sample4":"asd",
"Sample5":88,
"Sample6":null,
"Sample7":null,
"Sample8":null,
"Sample9":35,
"Sample0":35
}
]
}
]
}
And my goal is to go through the list of items (in my sample there is only one but there can be more) and if 'Available' is greater than 0 then save some values from 'Info' into a variable to use them for the next request.
Right now my solution is that I added JSON path postprocessor and there I separate the values like this:
$.Items[?(@.Available > 0)].Info[0].Sample1[0];
$.Items[?(@.Available > 0)].Info[0].Sample2[0];
$.Items[?(@.Available > 0)].Info[0].Sample3[0]...
but obviously this is not a very beautiful solution and I also think that this will take too much resource if I have to do it many times.
So my question is that is it somehow possible to separate the
$.Items[?(@.Available > 0)].Info[0]
element and then process it to get the fields I need?
Upvotes: 2
Views: 267
Reputation: 21
After I solved the problem for myself, then I completely forgot about this question. But I'll post my solution now if someone should be struggling with the same problem.
I'm sure there are ways how to solve this problem using JMeter but it got way too complicated for me to manipulate JSON with regular expressions and also I felt that this is a little ridiculous since there are so nice tools for this. So I wrote a little Java script using GSON, packed it into a .jar and added it to JMeter.
Upvotes: 0
Reputation: 168162
I believe you can do it in a single JSON Path query using an asterisk - *
- which stands for wildcard character like:
$.Items[?(@.Available > 0)].Info[0].*
References:
Upvotes: 1