Remove identity from role by ID via beta Patch Role API endpoint

Thanks for the information @chris_olive. I did some testing and was able to get the JSON path search that you described working to get the “negative list” (list of all identities except the one we want to remove) in a workflow. What I am running into now however, is that I can’t seem to find a way to construct the request body necessary to make the PATCH call for the removal. I have tried many different things but I believe the closest I got is this:

[{
    "op": "replace",
    "path": "/membership",
    "value": {
        "identities": "{{$.hTTPRequest.body.membership.identities[?(@.id != $.trigger.identity.id)]}}",
        "type":"IDENTITY_LIST"
    }
}]

This successfully takes the identity list returned from the HTTP request and gets the list of identities minus the one we are trying to remove, but it returns the list in a different format that is not proper JSON so the request fails. I did some research and found this topic about a similar issue and a response there that objects and arrays cannot be references with inline variables. Given that, do you have any suggestions for how I could put the pieces together to construct the body in a valid JSON format?

Thank you