1

I am writing a simple az command to return the default version of AKS. I have tried several variation as below, but the result set returned is the opposite of what I am after. Is there something I am missing with regards to the JMESPath filter expression and boolean values in the JSON?

These two commands, I would have thought, should return only the 'default' version. Instead, they return all but the default.

az aks get-versions -l $region --query "orchestrators[?default==true].[orchestratorVersion,default]" -o table

and

az aks get-versions -l $region --query "orchestrators[?default==true].{Version:orchestratorVersion,IsDefault:default}" -o table

In the end I used !=null filter instead, but would like to know the answer.

The data without the filter

az aks get-versions -l $region --query "orchestrators[].{Version:orchestratorVersion,IsDefault:default}" -o json 

is as follows:

[
  {
    "IsDefault": null,
    "Version": "1.10.12"
  },
  {
    "IsDefault": null,
    "Version": "1.10.13"
  },
  {
    "IsDefault": null,
    "Version": "1.11.9"
  },
  {
    "IsDefault": null,
    "Version": "1.11.10"
  },
  {
    "IsDefault": null,
    "Version": "1.12.7"
  },
  {
    "IsDefault": null,
    "Version": "1.12.8"
  },
  {
    "IsDefault": null,
    "Version": "1.13.11"
  },
  {
    "IsDefault": true,
    "Version": "1.13.12"
  },
  {
    "IsDefault": null,
    "Version": "1.14.7"
  },
  {
    "IsDefault": null,
    "Version": "1.14.8"
  },
  {
    "IsDefault": null,
    "Version": "1.15.4"
  },
  {
    "IsDefault": null,
    "Version": "1.15.5"
  }
]
NER1808
  • 1,829
  • 2
  • 33
  • 45

1 Answers1

2

This is a rule in the JEMSPATH, you can see the description here, it's the Raw type this document. And it shows below:

enter image description here

There is also a difference between PowerShell and Shell.

In PowerShell, you can just use the "``" in the command like this:

az aks get-versions -l $region --query "orchestrators[?default == ``true``].[orchestratorVersion,default]" -o table

But in Shell, you need to use the "`" and make change like this:

az aks get-versions -l $region --query 'orchestrators[?default == `true`].[orchestratorVersion,default]' -o table
Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • Thanks for that. I did read the JMESPath doc and thought I had tried every permutation! Didn't realise that using double quotes in Bash screwed it all up and never tried PowerShell. – NER1808 Nov 14 '19 at 18:29