azure-functions-core-tools icon indicating copy to clipboard operation
azure-functions-core-tools copied to clipboard

Arrays in local.settings.json no longer work for version 4

Open jamie-orangebees opened this issue 3 years ago • 2 comments

I recently upgraded to version 4 of the CLI for Mac using the recommended upgrade guide. After doing so the array functionality for local.settings.json no longer works. After reverting back the version 3 of the CLI it worked.

local.settings.json example below:

{
  "IsEncrypted": false,
  "Values": {
    "ExpirationNeverExpire:[0]": "311",
    "ExpirationNeverExpire:[1]": "2007",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

Reading settings code:

public static IServiceCollection AddExpirationConfiguration(this IServiceCollection services)
{
     services.Configure<List<string>>(_config.GetSection("ExpirationNeverExpire"));
}

...

public ExpireApplications
(
    IOptionsSnapshot<List<string>> expirationNeverExpire,
)
{
   // Version 4, Count = 0
   // Version 3, Count = 2
    _expirationNeverExpire = expirationNeverExpire.Value ?? new List<string>();
}

I tried this using Function v3 and v4. Neither worked with CLI version 4.

jamie-orangebees avatar Feb 24 '22 19:02 jamie-orangebees

I use arrays in v4 without the brackets like this:

"Values": {
    "SBInitConfig:InitItems:0:ConnectionString": "",
    "SBInitConfig:InitItems:0:Topic": "",
    "SBInitConfig:InitItems:0:Subscription": "",
    "SBInitConfig:InitItems:0:AutoDeleteTTLMinutes": -1,
    "SBInitConfig:InitItems:0:MessageTTLMinutes": 30

    "SBInitConfig:InitItems:1:ConnectionString": "",
    "SBInitConfig:InitItems:1:Topic": "",
    "SBInitConfig:InitItems:1:Subscription": "",
    "SBInitConfig:InitItems:1:AutoDeleteTTLMinutes": -1,
    "SBInitConfig:InitItems:1:MessageTTLMinutes": 30
}

pseabury avatar Mar 09 '22 15:03 pseabury

@pseabury That worked, thank you. @michaelpeng36 Is this in the migrations docs anywhere?

jamie-orangebees avatar Mar 22 '22 18:03 jamie-orangebees