This feature substitutes values in the JSON configuration files. It overrides the values in the specified JSON configuration files (for example, appsettings.json) with the values matching names of release pipeline and stage variables.
To substitute variables in specific JSON files, provide newline-separated list of JSON files. File names must be specified relative to the root folder.
If you want to substitute values in appsettings.json, enter the relative path from the root folder; for example content/website/appsettings.json. Alternatively, use wildcard patterns to search for specific JSON files.
For more details, you could refer to this article.
Answer from Joey Cai on Stack OverflowThis feature substitutes values in the JSON configuration files. It overrides the values in the specified JSON configuration files (for example, appsettings.json) with the values matching names of release pipeline and stage variables.
To substitute variables in specific JSON files, provide newline-separated list of JSON files. File names must be specified relative to the root folder.
If you want to substitute values in appsettings.json, enter the relative path from the root folder; for example content/website/appsettings.json. Alternatively, use wildcard patterns to search for specific JSON files.
For more details, you could refer to this article.
File Transform v2
Use this task to replace tokens with variable values in XML or JSON configuration files.
steps:
- task: FileTransform@2
displayName: 'Substitutes values in AppSettings.json'
inputs:
folderPath: '$(System.DefaultWorkingDirectory)/pathToFolder'
enableXmlTransform: false
jsonTargetFiles: appsettings.json

Variables
For example, to replace the value of ConnectionString in the sample file below, you need to define a variable as Data.DefaultConnection.ConnectionString in the build or release pipeline (or release pipeline's environment).
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\SQLEXPRESS;Database=MyDB;Trusted_Connection=True"
}
}
}

JSON=\''{"hostname": "localhost", "outdir": "'"$OUTDIR"'", "port": 20400, "size": 100000}'\'
That is get out of the single quotes for the expansion of $OUTDIR. We did put that expansion inside double-quotes for good measure even though for a scalar variable assignment it's not strictly necessary.
When you're passing the $JSON variable to echo, quotes are necessary though to disable the split+glob operator. It's also best to avoid echo for arbitrary data:
printf '%s\n' "$JSON"
If you ended up here trying to use AWS commands, @Stéphane Chazelas's answer almost works. In here, the initial escaped quotes (\') are not necessary, they actualy break the command.
IP=$(curl ipecho.net/plain ; echo)
aws ec2 authorize-security-group-ingress --group-id sg-**************** \
--ip-permissions '[{"IpProtocol": "tcp", "FromPort": 15000, "ToPort": 15000, "IpRanges": [{"CidrIp": "'"$IP/32"'", "Description": "Service A"}]}]'
^ This works just fine
Variable substitution with dynamic JSON
How can I replace these json values with variables?
substitute variables in appsettings.json file
How can I substitute values in a JSON file?
I am trying to make a python script which generates json. I know bash but not python.
I know this is easy, but I cannot figure it out. How do I replace these values with variables? I guess I don't how to call a variable like you can like this in bash: $variable
Thanks.
import json
person_json = {
"name": "Fred",
"place": "Melbourne",
"sex": "male",
"remote": { "addr": "Acacia Avenue", "id": "875932875392" },
"local": { "id": "8475974", "office": "Main" }
}When working with Slack APIs, it is very common to have huge blocks of JSON to work with. There are places in that JSON that you have to substitute with the values provided by queries in Django.
In my previous project, I maintained these JSON values in Python files and wrote my own substitution. But this time I feel like using JSON files given the project structure, I tried using render_to_string() but it's not very friendly if a user sends text from client/frontend including special characters.
Have you encountered such a problem before? Any other strategy I can try?