0

I am pulling policies from an azure keyvault

policies=$(az keyvault show --name $KeyVaultName --resource-group $ResourceGroupName --query "properties.accessPolicies")

Which returns some data like

[
  {
    "applicationId": null,
    "objectId": "0123b8ac-57a6-1234-9816-ff5swa4b6d0b",
    "permissions": {
      "certificates": [
        "Get",
        "Release"
      ],
      "keys": null
      "secrets": null,
      "storage": null
    },
    "tenantId": "abc-123"
  },
  {
    "applicationId": null,
    "objectId": "f4340076-d4ea-1234-a719-c75dfsat4d17",
    "permissions": {
      "certificates": null,
      "keys": [
        "Get",
        "Release"
      ],
      "secrets": null,
      "storage": null
    },
    "tenantId": "abc-123"
  }
]

Somehow I need to filter out the null permission objects, either by completely removing them or by replacing them with empty arrays. There could be any combination of policies. Is it possible to filter these out? I've been trying variations of jmespath and jq for hours and getting nowhere.

oguz ismail
  • 1
  • 16
  • 47
  • 69
Josh
  • 1,648
  • 8
  • 27
  • 58

1 Answers1

2

You're looking for something like this:

del(.[].permissions[] | nulls)

Online demo

oguz ismail
  • 1
  • 16
  • 47
  • 69