As you can see the picture below. I want to filter descriptor
value where subjectkind
is group
. The azure CLI command I am using to get the descriptor is
az devops security group membership list --id $var1 --org https://dev.azure.com/$OrgName/ --query "*.descriptor" --output tsv
It gives me the output but I am not able to filter the output based on the condition in the JMESPath query to get get the desired output.
FYI: I am using Windows PowerShell ISE
This is not a normal array of dictionary, here you can see the sub properties have same Key value pairs but the top node is different.
C:\Windows\system32> az devops security group membership list --id $var1 --org https://dev.azure.com/$OrgName/
enter code here
{
"aad.MDQwNjg0MDMtOWYwOC03OTM": {
"descriptor": "aad.MDQwNjg0MDMtOWYwOC03OTM",
"directoryAlias": "JoMarie.Jumbo",
"displayName": "Jo Marie Jumbo",
"domain": "78b2bd11",
"legacyDescriptor": null,
"mailAddress": "[email protected]",
"metaType": "member",
"origin": "aad",
"originId": "561b354c-527b-48ae",
"principalName": "[email protected]",
"subjectKind": "user",
"url": "https://vssps.dev.azure.com/mbie-sandbox/_apis/Graph/Users/aad.MDQwNjg0MDMtOWYwOC03OTM"
},
"aad.ZDJmMzI2ZDItOGM1ZS03NjQyLWExN2": {
"descriptor": "aad.ZDJmMzI2ZDItOGM1ZS03NjQyLWExN2ItOWQ",
"directoryAlias": "Paul.Jumbo",
"displayName": "Paul Jumbo",
"domain": "78b2bd11",
"legacyDescriptor": null,
"mailAddress": "[email protected]",
"origin": "aad",
"originId": "67c2bda2-b9ad-4843",
"principalName": "[email protected]",
"subjectKind": "user",
"url": "https://vssps.dev.azure.com/mbie-sandbox/_apis/Graph/Users/aad.ZDJmMzI2ZDItOGM1ZS03NjQyLWExN"
},
"aad.ZWUwODZlZTQtN2U3MC03M2U0LTk3": {
"descriptor": "aad.ZWUwODZlZTQtN2U3MC03M2U0LTk3",
"directoryAlias": "John.Jumbo",
"displayName": "John Jumbo",
"domain": "78b2bd11",
"legacyDescriptor": null,
"mailAddress": "[email protected]",
"origin": "aad",
"originId": "7c75ce3a-70a0-40e4",
"principalName": "[email protected]",
"subjectKind": "user",
"url": "https://vssps.dev.azure.com/mbie-sandbox/_apis/Graph/Users/aad.ZWUwODZlZTQtN2U3MC03M2U0LTk3"
},
CodePudding user response:
In order to filter on a dictionary, you can use an object projection, with *
.
With this you are coming back to an array, that you can further filter when the first projection has been stopped, with a pipe expression.
This gives you the query:
* | [?subjectkind == 'group'].descriptor
That, on this example JSON:
{
"aad.some_gibberish_characters_group_1": {
"descriptor": "aad.some_gibberish_characters_group_1",
"subjectkind": "group"
},
"aad.some_gibberish_characters_user_1": {
"descriptor": "aad.some_gibberish_characters_user_1",
"subjectkind": "user"
},
"aad.some_gibberish_characters_group_2": {
"descriptor": "aad.some_gibberish_characters_group_2",
"subjectkind": "group"
}
}
Would yield:
[
"aad.some_gibberish_characters_group_1",
"aad.some_gibberish_characters_group_2"
]