Substitute only in specific JSON file a specific value

Hey guys,

let’s say you have “Config*.json” as Target Files and you want to substitute only the value for the global key “Enabled” in one specific json file let’s say config1.json (but this key might be occur in a lot more). Is this somehow possible?

Maybe like the same with example you provide with representing the Json hierarchy “Data:DefaultConnection:ConnectionString”. So that the first information might be the filename: “config1:Enabled”?

Thanks in advance,
Florian

Hi Florian,

No this is not possible, but you can use the Substitute variables in files feature.

I hope that helps!

Thank you and best regards,
Henrik

Hey Henrik,

please excuse my late reply. We are aware of this feature of variable substitution in files and using it right now. The thing is that we have the actual configuration files (pre-defined, already substituted to say it that way) which are used for local deployment of our backend by developers and we have a template versions of these files which we use for deployment on different environments via Octopus (doing the substitution then).

Since the configuration files are JSON we thought we can get rid of the template version through using the JSON substitution feature and substitute in the actual file. And then we realized that it’s not possible to apply specific substitution to specific files and asked here :wink:

You might see another solution for this?

-Florian

Hi Florian,

I’d suggest you add a new ticket to our UserVoice site.

In the mean time, you could add the below PowerShell to a custom post-deploy script and it should replace the value in the file you want.

$pathToJson = "<PathToConfigs>\config1.json"
$a = Get-Content $pathToJson | ConvertFrom-Json
$a.Enabled = #{VariableWithTheValue}
$a | ConvertTo-Json | set-content $pathToJson

I hope that helps!

Thank you and best regards,
Henrik