Can't pass array to appsettings.json

usability
known
(Novikov Egor) #1

In article JSON Configuration Variables it is written:

You can also replace an entire array. For the example above you could set Octopus Variable foo:bar to a value of ["baz","qux"] .

But I failed to do it. Array of values is escaped in appsettings.json and stand in quotes.

this:

[ “*” ]

is transformed to this:

“\[ \”*\"\ ]"

How can I avoid this transformation when parameters are passed to appsettings.json file?

(Paul Calvert) #3

Hi @novikov.ea,

Thanks for getting in touch!

I’ve run a test on this using the following information.
appsettings.json in package:
{"foo":{"bar":["baz","qux"]}}

Variable in Octopus:
image

End result:

{
  "foo": {
    "bar": [
      "*",
      "*"
    ]
  }
}

If you can provide more details on the values you are using in each part I can run further tests on those.
Also, which version of Octopus Server are you using?

Best regards,
Paul

(Novikov Egor) #4

Version of Octopus Server: 2019.6.5

If you can provide more details on the values you are using in each part I can run further tests on those

My structure of appsettings.json is:

{
“Authentication”: {
“BusinessUsers”: null,
“MonitoringUsers”: null,
},
}

I want that Octopus changes parameters BusinessUsers and MonitoringUsers:

{
“Authentication”: {
“BusinessUsers”: [ “*” ],
“MonitoringUsers”: [ “*” ],
},
}

I set Authentication:BusinessUsers and Authentication:MonitoringUsers to [ “*” ]. But got:

{
“Authentication”: {
“BusinessUsers”: “\[ \”*\" \]",
“MonitoringUsers”: “\[ \”*\" \]",
},
}

I’ve found workaround. In appsettings.json I set not null but array with empty value

{
“Authentication”: {
“BusinessUsers”: [ “” ],
“MonitoringUsers”: [ “” ],
},
}

And set parameters
Authentication:BusinessUsers:0 = *
Authentication:MonitoringUsers:0 = *
Then I get what I want

{
“Authentication”: {
“BusinessUsers”: [ “*” ],
“MonitoringUsers”: [ “*” ],
},
}

It just workaround. But it’s wanted to have clear solution.
Paul, tell me please what data should I provide to you in order to find the truth?

(Paul Calvert) #5

Hi @novikov.ea,

Thanks for the additional detail, I can now replicate the same results that you’re seeing. It does look like a limitation where Octopus can replace values of an array fine, but isn’t able to create the array.

I’m going to have a chat with our engineers to see if this is expected behaviour, and if there is anything we could do to improve it.

Regards,
Paul

(Paul Calvert) #6

Hi @novikov.ea,

I’ve spoken with the engineers and this is due to the software looking at the type of the value in the JSON. So if the value is null, it isn’t able to determine whether the type should be any array or something else.

As you’ve discovered, the workaround for this is to set the value to either [""] or [] and then the variables will work as expected.

Regards,
Paul

(Novikov Egor) #7

Thank you, Paul, for your response.
So, I will use transformation from [] to array. I think it’s better solution than I had.

Thank you again for explanation.

1 Like