Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Custom query with more than one field on az ad sp list

Lets say I want to list id and appId from az ad sp list, how would one do that?

I get it working for only the id like this:

az ad sp list --query '[].id'

How can I extend this to id and appId?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I already tried

az ad sp list --query '[].id,[].appId'
az ad sp list --query '[].{id,appId}'

but both are invalid queries.

The output I am looking for should be something like

[
  {"id": 1, "appId": 2},
  {"id": 3, "appId": 4}
]

>Solution :

When doing a multiselect in JMESPath, you can re-key your objects, so you will need to specify both a new key and an existing key. Of course, the new key can be the same as the existing one.

So, if you don’t want to change the keys, your query should be:

[].{id: id, appId: appId}

And your Azure command:

az ad sp list --query '[].{id: id, appId: appId}'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading