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:
- use a JS-based jsonpath, (import a jsonpath JS module and do it in a JS callout)
- use a Java callout that takes advantage of a more recent jsonpath library, like this one: https://github.com/DinoChiesa/ApigeeEdge-Java-JSONPath (I built this to address similar limitations for other customers)
- pre-process your JSON to replace all boolean literals with strings, and THEN use the ExtractVariables with the string fiilter syntax
- transform the JSON to XML and use xpath