Found my answer. Two things were missing:
-
The jsonPath() function must be suffixed with .elementList() to produce a JSON-like result
-
The result of jsonPath needs to be processed by JSON.parse and JSON.stringify before it can be sent to S() and saved as a process var. Here’s the inline Javascript code that actually works, including the JSON creation for easy reference:
var rawData="[{“workId”:1,“orderId”:“1044”},{“workId”:2,“orderId”:“1044”},{“workId”:3,“orderId”:“1080”},{“workId”:4,“orderId”:“1081”}]";
var jsonData=S(rawData);
var targetVal = 3;
var query = “$.[?(@.workId<” + targetVal + “)]”;
var queryResult = jsonData.jsonPath(query).elementList();
var mySpin = S(JSON.stringify(JSON.parse(queryResult)));
execution.setVariable(‘finalOutput’, mySpin);