So close yet so far... I can return the resourceIds (extracted.StreamIds) but not a filtered list of "where isActive==true" (extracted.activeStreamIds).
This is grabbing a response from a ServiceCallout. Do I need to explicitly set the response to be application/json and if so, how would I do that?
<JSONPayload>
<Variable name="extracted.activeStreamIds">
<JSONPath>$.[?(@.isActive==true)].resourceId</JSONPath>
</Variable>
<Variable name="extracted.StreamIds">
<JSONPath>$..resourceId</JSONPath>
</Variable>
</JSONPayload>
Thanks!
Solved! Go to Solution.
hmm ok I've looked a little further.
using this example JSON
[ { "isActive" : "false", "resourceId" : 1 }, { "isActive" : "false", "resourceId" : 2 }, { "isActive" : "true", "resourceId" : 3 } ]
I have found that this jsonpath query works:
$[?(@.isActive == 'true')].resourceId
It returns an array with a single element, 3.
But using a json with boolean values instead of string values, like this:
[ { "isActive" : false, "resourceId" : 1 }, { "isActive" : false, "resourceId" : 2 }, { "isActive" : true, "resourceId" : 3 } ]
I could not find a query that worked as desired.
This does not work:
$[?(@.isActive == true)].resourceId
This query checks for the existence of the isActive property, not for its value:
$[?(@.isActive)].resourceId
...and yields [1,2,3], which I think is not what you want.
I think this is a limitation of the v0.8.0 jayway JSON Path library currently used by Apigee.
If I try this query
$[?(@.isActive == true)].resourceId
...with v2.4.0 of jayway, against a JSON file that uses boolean literals and not strings, it works as expected, returns [3] .
But you can't ask to use v2.4.0 of jayway in ExtractVariables. It is currently locked to v0.8.0.
There are other people who have asked for an upgrade to a current version of jsonpath, but for now it's not possible. The ticket that tracks the request to allow a more modern jsonpath is b/132486339 .
The workarounds available to you as I see them:
Glad to help, Peter!