ConvertFrom-Json not working in Azure Powershell

128 views Asked by At

So I have this powershell script:

$rawJsonData = az appconfig kv list --connection-string $env:APP_CONFIG_CONNECTION_STRING --fields key value

$keyValuePairs = $rawJsonData | ConvertFrom-Json

This works completely fine on my local powershell, but when I run it on my azure app service's docker container (through Kudu ssh), I get the following error:

ConvertFrom-Json : Invalid JSON primitive: _.

Here is an example of the structure I get:

[
  {
    "key": "any_key",
    "value": "any_value"
  },
  {
    "key": "any_key",
    "value": "any_value"
  }
]

I have verified that the object I receive on my local and in the azure powershell are the exact same. I have also verified that this occurs regardless of the key value fields (happens with both if I just specifiy one or the other alone).

It seems that on the azure side, it doesn't like an underscore character "_" that exists in my object, but I find that odd if it works on my local powershell. Any help to further debug this or resolve this would be greatly appreciated.

I have tried converting it to a string first with .ToString() I have also tried attaching --output json I have tried Get-Content -Raw... I have tried Invoke-WebRequest...

1

There are 1 answers

0
Daniyal Khawaja On

Okay guys, I found the issue. It seems that when I run the above in the Azure powershell environment it returns Hyper-v text and then the json, so my actual out put was:

_Hyper-v_text
{good_json_data}

The way it was resolved was by exporting the json data to a temp file (app_config.json) and then reading that back in:

# Create key/value pair dictionary JSON file from app config
az appconfig kv export -d file --path ./app_config.json --format json --skip-features --yes --connection-string $env:APP_CONFIG_CONNECTION_STRING
# Object with key-value pairs from app config
$keyValuePairs = (Get-Content -Path ./app_config.json -Raw) | ConvertFrom-Json