Search code examples
azure.net-coreappsettings

How to convert AppSettings.json to Advance Azure Settings with C#?


Did you notice that Azure upgraded the AppSettings Management? Now it s possible to update multiple AppSettings in one shot using the Advanced Edit Options, but the formating is not the same as AppSettings.json.

Azure Edit Options

I m looking for a quick solution to convert my AppSettings section to Azure Advance Edit options format. Do you know how to do that?

So this:

"Simulation": {
    "ApiUrl": "YourApiUrl",
    "ApiKey": "YouApiKey",
    "Groups": [
        {
            "Name": "YourGroup",
            "Latitude": 45.50884,
            "Longitude": -73.58781,
            "Radius": 500
        }
    ],
    "Planifications": [
        {
            "GroupName": "YourGroup",
            "At": "07:00",
            "Status": 10
        }
    ]
}

will be formatted like:

[
  {
    "Name": "Simulation:ApiUrl",
    "Value": "YourApiUrl",
    "SlotSetting": false
  },
  {
    "Name": "Simulation:ApiKey",
    "Value": "YourApiKey",
    "SlotSetting": false
  },
  {
    "Name": "Simulation:Groups:0:Name",
    "Value": "YourGroup",
    "SlotSetting": false
  },
  {
    "Name": "Simulation:Groups:0:Latitude",
    "Value": "45.50884",
    "SlotSetting": false
  },
  {
    "Name": "Simulation:Groups:0:Longitude",
    "Value": "-73.58781",
    "SlotSetting": false
  },
  {
    "Name": "Simulation:Groups:0:Radius",
    "Value": "500",
    "SlotSetting": false
  },
  {
    "Name": "Simulation:Planifications:0:GroupName",
    "Value": "YourGroup",
    "SlotSetting": false
  },
  {
    "Name": "Simulation:Planifications:0:At",
    "Value": "07:00:00",
    "SlotSetting": false
  },
  {
    "Name": "Simulation:Planifications:0:Status",
    "Value": "10",
    "SlotSetting": false
  }
]

Solution

  • There is a dotnet tool can do the conversion on Nuget dotnet-appsettings. It is required .NET 3.1 SDK.

    dotnet tool install --global dotnet-appsettings
    dotnet tool list --global
    Usage: appsettings [appsettings.json]