billa Thanks for posting your question in Microsoft Q&A. As per doc: Local settings file, Values
must be strings and not JSON objects or arrays.
However, you can define the values like below in the local.settings.json
file (also application setting in azure; use__
for Linux instead of :
) and use dependency injection to bind the values.
Local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"ToAddress:0:Mail1": "******@gmail.com",
"ToAddress:0:Mail2": "******@hotmail.com",
"ToAddress:0:Mail3": "******@honda.com"
}
}
Startup.cs (Check Use dependency injection in .NET Azure Functions for detailed info about the dependency injection)
[assembly: FunctionsStartup(typeof(HttpTriggerParse.Startup))]
namespace HttpTriggerParse
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddOptions<List<MailAddress>>()
.Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection("ToAddress").Bind(settings);
});
}
}
}
Function1.cs
public class Function1
{
private List<MailAddress> ToAddress;
public Function1(IOptions<List<MailAddress>> mailAddresses)
{
ToAddress = mailAddresses.Value;
}
[FunctionName("Function1")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
string responseMessage = string.IsNullOrEmpty(name)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $"Hello, {name}. This HTTP triggered function executed successfully.";
return new OkObjectResult(responseMessage);
}
}
Output:
Also, check out similar discussion in SO thread and that might assist you with some questions. I hope this helps and let me know if you have any questions.
If you found the answer to your question helpful, please take a moment to mark it as "Yes" for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions