0

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"
}
TheDoomDestroyer
  • 2,434
  • 4
  • 24
  • 45
  • 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. – Daniel Mann Oct 08 '20 at 15:03
  • Hi friend, any update for this issue? – LoLance Oct 15 '20 at 10:11

2 Answers2

1

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:

enter image description here

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).

halfer
  • 19,824
  • 17
  • 99
  • 186
LoLance
  • 25,666
  • 1
  • 39
  • 73
0

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.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • It has nothing to do with .NET specifically. The question literally asks how to add values to a .json file without losing anything that hasn't been overwritten. – TheDoomDestroyer Oct 09 '20 at 05:31