1

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

lekiniu
  • 61
  • 1
  • 1
  • 8

1 Answers1

0

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.

Edward Han-MSFT
  • 2,879
  • 1
  • 4
  • 9
  • thank you for response:) I am also looking for authors feedback too – lekiniu Feb 19 '21 at 08:47
  • Hi lekiniu, You could try to replace the element by reference to my transformations and let me know if it works for you too. Looking forward for your reply. – Edward Han-MSFT Feb 19 '21 at 09:03
  • Does my replace transformations work for you too? Please try it and kindly let me know the result. – Edward Han-MSFT Feb 22 '21 at 03:23
  • unfortunately, it works differently even when I want to replace, it puts variables in appsettings.json : "my_array[0]": { "value": "3" } – lekiniu Feb 22 '21 at 06:40
  • Is your appsettings.json exactly the same with me```{ "my_array" : [ {"value" : 1}, {"value" : 5} ] }``` If yes, you can then use replace transformations ```{ "my_array[0]/value" : 3 }``` to get the same result as mine. – Edward Han-MSFT Feb 22 '21 at 07:02