Using jsonPath to filter data ... what's the Camunda syntax?

Found my answer. Two things were missing:

  1. The jsonPath() function must be suffixed with .elementList() to produce a JSON-like result

  2. 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);

3 Likes