Reputation: 3065
I have a JSON file that I'd like to "overwrite" with data from another JSON, but keep anything that isn't changed. Is there a way to do this out of the box for Azure DevOps pipeline releases? There is a Config transform plugin thingy for it named magic-chunks, but its syntax is really odd and doesn't work properly if I need to overwrite an array.
Destination (JSON that should be "overwritten")
{
"AppSettings": {
"AllowSwaggerRequests": false,
"Secret": "SomeStuff"
},
"Logging": {
"LogLevel": {
"Default": "Debug"
}
}
}
JSON that should be used and added on top of the previous one.
{
"AppSettings": {
"AllowSwaggerRequests": true,
"Secret": "Overwritten"
},
"TestProperty": "Hello World"
}
Expected result:
{
"AppSettings": {
"AllowSwaggerRequests": true,
"Secret": "Overwritten"
},
"Logging": {
"LogLevel": {
"Default": "Debug"
}
},
"TestProperty": "Hello World"
}
Upvotes: 0
Views: 249
Reputation: 3065
The solution suggested by LoLance back in the day did not help sadly and I had given up on it altogether. Funnily enough, some time later I had managed to find an Azure DevOps extension / plugin called "File Patch Build and Release Tasks" (I am unable to find the link to it right now for some reason) which I used and which worked really. Its syntax was a bit unusual, but it did the job.
Upvotes: 0
Reputation: 28196
Overwrite JSON in TFS releases
As I know there's no such task from extensions that can be used to Overwrite+Add node
at the same time.
One alternative way is to use PS script to modify the Json content like what Krzysztof Madej suggested below your question. (His answer was deleted hours ago but I don't know why...)
Also you can consider overwriting the whole json file via free File Creator task. You can define different content here for different stages in your release:
Just write the content you want it to be, and you don't need to care about the transform syntax. (Enable Overwrite file if exists
).
Upvotes: 1
Reputation: 59045
This is an X/Y problem. You can specify multiple configuration files for a .NET Core application -- i.e. appsettings.json
which contains general values and appsettings.dev.json
that contains environment-specific overrides. Refer to the documentation on configuration.
Upvotes: 0