Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse json output due to duplicate keys #27698

Open
kamalca opened this issue Oct 26, 2023 · 2 comments
Open

Cannot parse json output due to duplicate keys #27698

kamalca opened this issue Oct 26, 2023 · 2 comments
Assignees
Labels
Auto-Assign Auto assign by bot Azure CLI Team The command of the issue is owned by Azure CLI team Compute az vm/vmss/image/disk/snapshot question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Milestone

Comments

@kamalca
Copy link

kamalca commented Oct 26, 2023

Describe the bug

Some commands return json values with duplicate keys when case-insensitive.

Here is an example:

az vm list-skus --location centralus --size "Standard_D4s_v5" --all -o json | ConvertFrom-Json

ConvertFrom-Json : Cannot convert the JSON string because a dictionary that was converted from the string contains the
duplicated keys 'Name' and 'name'.
At line:1 char:9
+ $json | ConvertFrom-Json
+         ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [ConvertFrom-Json], InvalidOperationException
    + FullyQualifiedErrorId : DuplicateKeysInJsonString,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

This is also an issue with ConvertFrom-Json not being case-sensitive. However, is it possible to restrict the output of az cli to not include duplicate case-insensitive keys?

The other reason I point this out is because the name field is not really being used:

...
"zoneDetails": [
  {
    "Name": [
      "3",
      "2",
      "1"
    ],
    "capabilities": [
      {
        "name": "UltraSSDAvailable",
        "value": "True"
      }
    ],
    "name": null
  }
],
...

This lowercase 'name' being set to null seems to not be serving any purpose.

Related command

az vm list-skus

Errors

ConvertFrom-Json : Cannot convert the JSON string because a dictionary that was converted from the string contains the
duplicated keys 'Name' and 'name'.

Issue script & Debug output

N/A

Expected behavior

Any command with -o json being piped to ConvertFrom-Json should always successfully result in an object.

Environment Summary

"azure-cli": "2.53.1",
"azure-cli-core": "2.53.1",
"azure-cli-telemetry": "1.1.0",
"extensions": {}

Additional context

No response

@kamalca kamalca added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Oct 26, 2023
@yonzhan
Copy link
Collaborator

yonzhan commented Oct 26, 2023

Thank you for opening this issue, we will look into it.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Compute az vm/vmss/image/disk/snapshot label Oct 26, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added Auto-Assign Auto assign by bot Azure CLI Team The command of the issue is owned by Azure CLI team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Oct 26, 2023
@yonzhan yonzhan added this to the Backlog milestone Oct 26, 2023
@yonzhan yonzhan removed the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Oct 26, 2023
@ManjulaChintharla
Copy link

I am also getting similar error during ARM deployment .

ConvertFrom-Json : Cannot convert the JSON string because a dictionary that was converted from the string contains
the duplicated keys 'eTag' and 'etag'.
At ..............................-Deploy.ps1:124 char:58

  • ... me = $(az aks list -g $resourceGroup -o json | ConvertFrom-Json).name
  •                                                ~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [ConvertFrom-Json], InvalidOperationException
    • FullyQualifiedErrorId : DuplicateKeysInJsonString,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

Can you please suggest any fix ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot Azure CLI Team The command of the issue is owned by Azure CLI team Compute az vm/vmss/image/disk/snapshot question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

5 participants