Try this.
$.requestedItemsStatus[?(@.name == "AD-Exchange-Online" || @.name == "AD-Exchange-Onprem")].approvalInfo[?(@.approvalDecision == "APPROVED")]
I used https://www.javainuse.com/jsonpath to test this because it matches very closely to our JSONpath implementation for triggers. The first part of this filter will filter out any requested item that doesn’t match one of those names. Here is the resulting JSON:
$.requestedItemsStatus[?(@.name == "Engineering Access" || @.name == "Engineering Access 2")]
[
{
"clientMetadata": {
"applicationName": "My application"
},
"approvalInfo": [
{
"approver": {
"name": "William Wilson",
"id": "2c91808568c529c60168cca6f90c1313",
"type": "IDENTITY"
},
"approvalDecision": "APPROVED",
"approvalComment": "This access looks good. Approved.",
"approverName": "Stephen.Austin"
}
],
"name": "Engineering Access",
"description": "Access to engineering database",
"comment": "William needs this access to do his job.",
"id": "2c91808b6ef1d43e016efba0ce470904",
"type": "ACCESS_PROFILE",
"operation": "Add"
},
{
"clientMetadata": {
"applicationName": "My application"
},
"approvalInfo": [
{
"approver": {
"name": "William Wilson",
"id": "2c91808568c529c60168cca6f90c1313",
"type": "IDENTITY"
},
"approvalDecision": "REJECTED",
"approvalComment": "This access looks good. Approved.",
"approverName": "Stephen.Austin"
}
],
"name": "Engineering Access 2",
"description": "Access to engineering database 2",
"comment": "William needs this access to do his job.",
"id": "2c91808b6ef1d43e016efba0ce470905",
"type": "ACCESS_PROFILE",
"operation": "Add"
}
]
Then, to filter out the non-approved items, select the approvalInfo
object and run another filter:
$.requestedItemsStatus[?(@.name == "Engineering Access" || @.name == "Engineering Access 2")].approvalInfo[?(@.approvalDecision == "APPROVED")]
[
{
"approver": {
"name": "William Wilson",
"id": "2c91808568c529c60168cca6f90c1313",
"type": "IDENTITY"
},
"approvalDecision": "APPROVED",
"approvalComment": "This access looks good. Approved.",
"approverName": "Stephen.Austin"
}
]