How to store JSON value within azure key vault

Viewed 2987

I am straggling to understand what is the best practice to store data in json format within azure key vault or alternatively to map each single key to my "appsettings.json" files. i read a lot on that issue but i couldn't figure it out how exactly it can be done

How would i retrieve json string formatted and map it to an object or assign each key vault into my appsettings.json

This is how my json looks like.

{
   "Container":{
      "Machine1":{
         "url":"some address "
      }
    }
}

Thanks, appreciate a lots your help

2 Answers

Of course, you can store JSON value to azure keyvault, follow the steps below.

1.Install the Az powershell module, follow this doc - https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-3.8.0

2.Then use Connect-AzAccount to login your account, make sure your account has the correct secret permission in Access policies of your keyvault, if not, add it in the portal.

3.Then use the commands below(you cannot store the json value directly in the portal, the Azure Portal currently only supports single-line secret values).

$string = '{
   "Container":{
      "Machine1":{
         "url":"some address "
      }
    }
}'
$Secret = ConvertTo-SecureString -String $string -AsPlainText -Force
Set-AzKeyVaultSecret -VaultName "keyvaultname" -Name "testjson" -SecretValue $Secret

4.Check it in the portal -> your keyvault -> Secrets, it works fine.

enter image description here

Related