How do I get a json variable replaced without it being placed in quotes ?
The appsettings.json
contains a list of server names, server:names
is an Octopus deploy variable that need to be replaced on deployment.
{
"server":
{
"names": [ "#{server:names| JsonEscape}" ]
}
}
Octopus variable is configured like this:
server:names
with value: "server_x", "server_y"
The result for names after replacement should be:
"names": [ "server_x", "server_y" ]
but instead I'm getting the following result which makes the json file invalid:
"names": [ ""server_x", "server_y"" ]
Appsettings.json
needs the quotes but should be replaced by the Octopus Deploy. I can't use the Json Configuration Variables
feature, it needs to substitute the variables.
Any ideas how I would go about this ?
If you can't use the Json Configuration Variables (now Structured configuration variables feature), I think the way to go is:
["server_x", "server_y"]
"names": #{server:names}
Note: JsonEscape is for escaping values that will go into JSON strings, not full JSON elements or nodes.
If you need to escape the server names, you may need to do that for the server names individually.
In your original example, you can remove the extra "s to get valid JSON. Or using my example above without JsonEscape produces the expected structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With