DONT JSON Escape variable value

Trying to use the variable substitution feature of octopus deploy. Its modifying a json file. I have specific values I have in the format of Text. its got 2 slashes in the value. So the value is ‘DOMAIN\user’, but when it substitutes in the json file, it escapes the slashes to ‘DOMAIN\\user’. How do I turn this off? Cant find a dontMessWithThisValue filter.

Also, Feature request: I should be able to delete or add keys to a JSON file in this variable replacement feature. Such that different environements require different key value pairs altogether, and I cant delete or add key/values if the variable doesnt match an existing key in the json.

So \ char isnt valid JSON in a string, so I get it, but when I try to use the hex value, you dont convert…You should convert to hex for me and back out. What if a complex password was in the value being written? I have been able to confirm that even if you set the value type to PASSWORD, the char gets escaped, so when it encounters a \ in a JSON var replacement, it comes out \.

Hi Brandon,

Thanks for getting in touch!

You’re right, when we are processing a JSON file we will escape characters as you describe. This is 100% intentional, as we are conforming to the spec. What I suspect you are doing here is reading the file back as text, rather than using a JSON converter (e.g. ConvertFrom-JSON in Powershell)

As for your feature request, one way to do this would be using our Configuration Transforms feature. The limitation here is that you will need to update the entire JSON blob, it isn’t smart enough to be able to insert variables in the file directly. In reality, we have designed Octopus around the concept that the package, and thus the files within the package, should be the same regardless of environments that you are deploying to. What we would expect here is that your variables, or key:value pairs, would be in the file as NULL or safe values which we would then replace per environment where needed.

I hope that helps, any questions please let me know!


1 Like

Thanks Alex, my confusion. I understand it now that its a JSON file, so you encode it to safe text for JSON. Got it working.

1 Like