Hi there, I’m trying to substitute an array into JSON through the Octopus Variable. I’m seeing that Arrays are supported but it seems like it won’t substitute a group of values as an array.
This is what I’m trying to do.
So that when it replaces this in appsettings.
It should turn out like this.
But it gives me this error.
Thanks for getting in touch! I’m very sorry for the delay in getting back to you. I have some helpful information here though.
Your approach is close but not quite there. I managed to get this working on my VM by doing the following:
The JSON file I used to test this looked like this:
Octopus was able to successfully transform this file into the following:
So I believe you are a nearly there. Your variable values need to be encapsulated with double quotes, square brackets and comma separated.
Let me know if this helps or if you have any further questions, and again I am sorry for the delayed response.
A note about an edge case I discovered that is not explicitly mentioned in the documentation. The replaced value MUST be an array already, otherwise JSON Variable Replacement replaces the variable as a string.
I originally had:
AllowedOrigins: ["Value1", "Value2"]
The replaced file ended up with:
"AllowedOrigins": "[\"Value1\", \"Value2\"]"
The workaround was to explicitly “declare” the empty array:
This is a bit unfortunate since the consuming code may have different interpretations of an empty array versus a missing array.