Adding array element in Appsettings.Json, on Azure Devops Release Pipeline Via magic chunks Config transformation

Viewed 856

I am using magic chunks Config transformation on azure devops release pipeline, I am trying to add array element in appsettings.jason, but I could not find any real example how to to it, I created array with following code ->

 "my_array[]`0', 

but it gave result like this :

{
      "my_array" : 
     [
       "value" : 1,
     ]
 }

it could not add object element in it, I want to create following json in appsetting :

{
      "my_array" : 
     [
       {"value" : 1},
       {"value" : 5}
     ]
 }

I found that the following code must work but it does not :

   my_array[]`0/@value

enter image description here

1 Answers

It seems that you have installed this 3rd-party extension: Magic Chunks in organization. After testing in my side , I get below findings. Below is appsetting.json.

{
      "my_array" : 
     [
       {"value" : 1},
       {"value" : 5}
     ]
}

I can then replace its element with following transformations.

{
      "my_array[1]/value" : 3
}

enter image description here And then the result is below.

{
  "my_array": [
    {
      "value": 1
    },
    {
      "value": "3"
    }
  ]
}

However, it always fail if I try to add an element using following transformations.

{
      "my_array[2]/value" : 5
}

or

{
      "my_array[0]/value" : 1,
      "my_array[1]/value" : 3,
      "my_array[2]/value" : 5
}

And so on. It seems adding new element is not supported. In the meanwhile, I see you have submitted this feedback here: https://github.com/magic-chunks/magic-chunks-dotnetcore/issues/131, I will monitor it and wish for the author's feedback.

Related