Octo variable substitution on appsetttings.json nested objects

Yo,

So I have an appsettings.json file in one of my .net core apps, and it has a section of JSON which is an array of unnamed objects, all of which I want to replace the same variable, “minLevel”

"NLog": {
 "rules": [
      {
        "logger": "*",
        "minLevel": "Info",
        "writeTo": "Splunk",
        "filterDefaultAction": "Log",
      },
      {
        "logger": "*",
        "minLevel": "Info",
        "writeTo": "Console"
      }
    ]
}

So in Octo what I have right now for a variable substitution is

NLog:rules:minLevel

But this doesn’t do the trick. What exactly IS the syntax to search through all those nodes and replace ALL the minValue values with a given value?

Cheers

Hi Chris,

Thanks for getting in touch! Octopus expects a zero-based index identifier when replacing objects in a JSON array. So you will need to create two variables to edit the minLevel for both of these nested objects.

Variable Value
NLog:rules:0:minLevel NewValue
NLog:rules:1:minLevel NewValue

Our documentation on structured configuration variables covers this with some example. As a note, I just did a quick test with wildcard indexing and can confirm that it doesn’t work. Hence the need for a unique variable for each index in the array.

Let me know if this helps, and if you have any questions at all, don’t hesitate to ask.

Best regards,
Daniel

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.