For the case of returning an array of complex JSON objects from configuration, I've adapted @djangojazz's answer to use anonymous types and dynamic rather than tuples.
Given a settings section of:
"TestUsers": [
{
"UserName": "TestUser",
"Email": "[email protected]",
"Password": "P@ssw0rd!"
},
{
"UserName": "TestUser2",
"Email": "[email protected]",
"Password": "P@ssw0rd!"
}],
You can return the object array this way:
public dynamic GetTestUsers()
{
var testUsers = Configuration.GetSection("TestUsers")
.GetChildren()
.ToList()
.Select(x => new {
UserName = x.GetValue<string>("UserName"),
Email = x.GetValue<string>("Email"),
Password = x.GetValue<string>("Password")
});
return new { Data = testUsers };
}