Hi folks, I have a Spin JSON var (shown below) in which all elements have the same set of fields.
I want to query the JSON to extract a subset of elements and create a process variable from the result. For instance, get all elements whose groupId == “A” (i.e. a subset of the original JSON)
I’m doing this in a script task (inline Javascript code below) but when I start the process I get error, "cannot serialize object in variable ‘myData’. How should I set up the jsonPath query? Alternatively, how should I manipulate ‘result’ to get it into a process variable (I’ve tried S(result) with no success)
Contents of JSON variable ‘myData’:
[
{
"workId": 1,
"orderIdType": "PO",
"groupId": "A"
},
{
"workId": 2,
"orderIdType": "Other",
"groupId": "A"
},
{
"workId": 3,
"orderIdType": "Other",
"groupId": "B"
},
{
"workId": 4,
"orderIdType": "PO",
"groupId": "B"
}
]
Contents of the script task (Javascript, inline script):
var myQuery = "$.[?(@.groupId==\'A\')]";
var result = myData.jsonPath(myQuery);
execution.setVariable('queryResult', result);
Much appreciated!