I am trying to create the below json structure and wanted to keep appending values only under policy defination , but how do i store and add new values along with existing values ? can someone please provide sample c# or idea on how to do it ?
How the output should look like
{
"properties": {
"displayName": "Cost Management",
"description": "Policies to enforce low cost storage SKUs",
"metadata": {
"category": "Cost Management"
},
"parameters": {
"namePrefix": {
"type": "String",
"defaultValue": "myPrefix",
"metadata": {
"displayName": "Prefix to enforce on resource names"
}
}
},
"policyDefinitions": [
{
"policyDefinitionId": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1",
"policyDefinitionReferenceId": "Limit_Skus",
"parameters": {
"listOfAllowedSKUs": {
"value": [
"Standard_GRS",
"Standard_LRS"
]
}
}
},
{
"policyDefinitionId": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming",
"policyDefinitionReferenceId": "Resource_Naming",
"parameters": {
"prefix": {
"value": "[parameters('namePrefix')]"
},
"suffix": {
"value": "-LC"
}
}
}
]
}
}
What I have tried:
below is the sample code am trying with sample schema
<pre>if (!blockBlob.Exists())
{
JObject js = new JObject(
new JProperty("properties",
new JObject(
new JProperty("displayName", (object)jobject["properties"]["displayName"]),
new JProperty("description", (object)jobject["properties"]["description"]),
new JProperty("policyDefinations",
new JArray(new JObject(
new JProperty("assignedBy", "jaya"))))
)));
modifiedfile = js.ToString();
await blockBlob.UploadTextAsync(modifiedfile);
Console.WriteLine(file);
}
else
{
var ms = new MemoryStream();
var policyData = blockBlob.DownloadText();
var currentJObject = JObject.Parse(policyData);
var currentArray = (JArray)currentJObject["properties"]["policyDefinations"];
var data = JsonConvert.DeserializeObject<PolicyJsonEntity>(policyData);
currentArray.AddAfterSelf(new JObject(
new JArray(new JObject(
new JProperty("assignedBy", "jaya")))));