In appsettings.json
{
\"MyArray\": [
\"str1\",
\"str2\",
\"str3\"
]
}
In Startup.cs
Kind of an old question, but I can give an answer updated for .NET Core 2.1 with C# 7 standards. Say I have a listing only in appsettings.Development.json such as:
"TestUsers": [
{
"UserName": "TestUser",
"Email": "Test@place.com",
"Password": "P@ssw0rd!"
},
{
"UserName": "TestUser2",
"Email": "Test2@place.com",
"Password": "P@ssw0rd!"
}
]
I can extract them anywhere that the Microsoft.Extensions.Configuration.IConfiguration is implemented and wired up like so:
var testUsers = Configuration.GetSection("TestUsers")
.GetChildren()
.ToList()
//Named tuple returns, new in C# 7
.Select(x =>
(
x.GetValue("UserName"),
x.GetValue("Email"),
x.GetValue("Password")
)
)
.ToList<(string UserName, string Email, string Password)>();
Now I have a list of a well typed object that is well typed. If I go testUsers.First(), Visual Studio should now show options for the 'UserName', 'Email', and 'Password'.